I have a computer science test on Monday which will have a very
similar question to the one below. If you could please have an answer
before Sunday, I would greatly appreciate it!! I am completely new to
java and want to see the code for this so that I can study and
understand it. The question is:
Create a Triangle class that implements all of the missing code from
the template below (fill in the missing code):
public class Triangle
{
private Coordinate a, b, c;
//default constructor: should generate random Coordinates
public Triangle();
//standard constructor
public Triangle(Coordinate newA, Coordinate newB, Coordinate newC);
//accessors
public Coordinate getVertexA();
public Coordinate getVertexB();
public Coordinate getVertexC();
public double getSideA();
public double getSideB();
public double getSideC();
public double getAngleA();
public double getAngleB();
public double getAngleC();
public boolean isValid();
public boolean isScalene();
public boolean isIsosceles();
public boolean isEquilateral();
public double getPerimeter();
public double getArea();
public String toString();
public boolean equals(Object o);
public boolean contains(Coordinate t);
public Circle getCircumcircle();
public Circle getIncircle();
}
That's all for the question.
Some auxiliary classes you may want to use to help you out:
public class Coordinate
{
//state variable(s)
private double x;
private double y;
//constructor function(s)
public Coordinate();
public Coordinate(double newX, double newY);
public Coordinate (Coordinate toBeCopied);
//accessor function(s)
public double getX();
public double getY();
//utility function(s)
public double distanceTo(Coordinate target)
{
double deltaX = x - target.getX();
double deltaY = y - target.getY();
double hypotSquared = (deltaX * deltaX) + (deltaY * deltaY);
return (Math.sqrt(hypotSquared));
}
public String toString()
{return ("(" + x + "," + y + ")")}
}
public class Circle
{
private Coordinate origin;
private double radius;
public Circle();
public Circle(Coordinate newOrigin, double newRadius);
} |