Question: II . Enhancing a Triangle Class Part A In Desire 2 Learn you will find a . zip archive containing two Java classes: CartesianPoint.java and

II. Enhancing a Triangle Class
Part A
In Desire2Learn you will find a .zip archive containing two Java classes: CartesianPoint.java and Triangle.java. Download and unzip that file. Compile both classes.
Part B
Add the following methods to the Triangle class:
public double getPerimeter()- returns the perimeter of the triangle.
public boolean isEquilateral()- returns true if the triangle is an equilateral triangle, false otherwise.
public boolean isRight()- returns true if the triangle is a right-angle triangle, false otherwise. (Hint: C an use the Pythagorean Formula).
Note: make use of methods in the CartesianPoint.java
Consult math texts or online sources if you forget the definitions of "equilateral" or "right-angle", or if you can't recall a formula.
IMPORTANT NOTE regarding equality comparisons1: When working with floating-point numbers in Java (or any programming language), calculations don't work out exactly as we might expect. For instance, we may perform some calculations and end up with an answer like: 3.999999... instead of the expected answer of 4. This happens because of the limited precision used to store/represent floating-point numbers in a computer.
Therefore, rather than comparing two double values using:
you should instead calculate the difference between the two numbers and then compare that to some really, really small value. If the difference is less than that re ally small value, then the two numbers are, essentially, equal.
For example, use:
if (Math.abs (num1-num2) TOLERANCE){...
where double TOLERANCE =1E-14(or some other really small number).
Aside: Math.abs (num1-num2) simply gives the absolute value of the difference betwe n num1 and num2.
Continued on the next page...
?1 See also: Section 5.3 of the course textbook.
Part C
In a separate file, create a test driver that exercises the two new methods in your Triangle class; name this class TestTriangle. In your test driver, create at least 2 Triangle objects (one that is an equilateral triangle, and another that is a right triangle). Call both methods on each of these objects and print out the results in a meaningful way, such as "The triangle t2 is not an equilateral triangle" or "The triangle t2 is a right-angle triange." Compile and run this program. Examine the output and return to part b if you notice any problems. Once it is running correctly, please save sample output.
Hint (if you're having trouble coming up with test data): For an equilateral triangle you can use the points ath.sqrt 32, and for a right triangle you can use (0.0,0.0),(1.0,0.0),(0.0,1.0).
??****
This class represents a triangle shape using 3 points.
@author Natalie Webber
**?
public class Triangle {
private CartesianPoint pointA;
private CartesianPoint pointB;
private CartesianPoint pointC;
public Triangle (double x1, double y1,
double x2, double y2,
double x3, double y3){
point A= new CartesianPoint (x1,y1);
pointB = new CartesianPoint (x2,y2);
}
pointC = new CartesianPoint (x3,y3);
public Triangle (CartesianPoint p1,
CartesianPoint p2,
CartesianPoint p3){
pointA =p1;
pointB = p2;
}
pointC = p3;
}
public class CartesianPoint {
??****
The x value for the point.
****?
private double xi
??****
The y value for the point.
****?
private double y;
??****
Constructs a CartesianPoint object with the
given x and y values.
@param xVal the initial x value.
@param yVal the initial y value.
****?
public CartesianPoint (double xVal, double yVal){
x=xVal;
}
y=yVal;
??****
Calculates the distance between this
CartesianPoint and the specified one.
@param 2 the x value for the other point.
@param y2 the y value for the other point.
@return the distance between the two points.
****?
public double distance (double x2, double y2){
double dx=x-x2;
double dy =y-y2;
 II. Enhancing a Triangle Class Part A In Desire2Learn you will

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!