The project will be submitted electronically through WebCT. Zip up your entire project directory for submission. (Right click on the project folder, follow the Send To link and select Compressed (zipped) Folder.) Once the compression process is done, you will have a zipped file with the same name as your project folder and an extension of .zip. This zipped file will be uploaded to the WebCT system during project submission. The project directory should include the following files:
You have been asked to write a program that calculates the area of a triangle given the lengths of its three sides. In addition, your program should be able to calculate the base and height of the triangle assuming that the first length is the base of the triangle.
Heron's Formula provides a way to calculate the area of a triangle given the lengths of its three sides. If a, b and c are the lengths, then the area can be computed as follows.
First, compute s as:
Next, compute area as:
s =
a + b + c 2
area = square root of (s * (s - a) * (s - b) * (s - c))Assuming that a corresponds to the base of the triangle, and given that the area also equals base times height divided by 2, we can compute base and height as:
base = a
height =
2 * area base
Use the Math.sqrt method to compute the square root of a number. For example, Math.sqrt(2) computes the square root of 2.
myA - a double value representing the first lengthConstructors:
myB - a double value representing the second length
myC - a double value representing the third length
/* The constructor has three parameters: */Methods:
/* the lengths of the triangle's sides. */
public Triangle(double a, double b, double c)
/* getArea returns the area */
public double getArea()/* getBase returns the base */
public double getBase()/* getHeight returns the height */
public double getHeight()/* setA sets the first length to a new value */
public void setA(double a)/* setB sets the second length to a new value */
public void setB(double b)/* setC sets the third length to a new value */
public void setC(double c)/* toString returns a string describing the triangle, */
/* including the lengths, area, base and height. */
public String toString()