Question: Make the following two classes (you can add other methods, Constructors, and instance variables, if necessary ): 1.) class Triangle Instance Variables: height, base Methods:

Make the following two classes (you can add other methods, Constructors, and instance variables, if necessary):

1.) class Triangle

Instance Variables: height, base

Methods: setHeight(), setBase(),getHeight(), getBase(), displayArea().

2.) class Circle

Instance Variables: radius

Methods: setRadius(),getRadius(),displayArea().

Use the following Tester class (you are NOT allowed to add any code to the Tester class)

public class Tester {

public static void main(String[] args) {

Triangle myTriangle = new Triangle();

Triangle yourTriangle = new Triangle();

Circle myCircle = new Circle(6);

Circle yourCircle = new Circle(6);

myTriangle.setHeight(8);

myTriangle.setBase(4.7);

myTriangle.displayArea();

System.out.println(myTriangle == yourTriangle);

System.out.println(myCircle == yourCircle);

System.out.println(myTriangle.equals(yourTriangle));

System.out.println(myCircle.equals(yourCircle));

System.out.println(myTriangle.toString());

System.out.println(Circle.radius);

System.out.println(Circle.displayArea(5));

System.out.println(yourCircle.displayArea());

}

}

The output should be:

0.0

false

false

false

true

This is a triangle

6.0

78.5

113.097

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!