Shape.java
Budget: $30 – $250 USD
You will be given a main() method inside the Shape class. You are going to construct 2 other
classes to make the given main() run successfully.
a. Construct a new class named as “triangle” to store information of some right
triangle shapes. This class contains three parameters: double height, double
base, String color
i. Make two constructors for this class. One only initializes the object with a
String indicating this shape’s color. Another one initializes all three
attributes (height, base, color) for the new object. Check the offered
main() to order the parameters for the constructors.
ii. Write the accessors and mutators methods for these three attributes.
iii. Write a method area() to calculate the triangle’s area by:
???????????? =ℎ???ℎ?∗???? /2
This public method receives no parameters (using the class attributes)
and return a double.
b. Construct a new class named as “circle” to store information of some circle
shapes. This class contains three parameters: double radius, String color, final
static double PI = 3.14
i. Make two constructors for this class. One only initializes the object with a
String indicating this shape’s color. Another one initializes radius and
color for the new object. Check the offered main() to order the
parameters for the constructors.
ii. Write the accessors and mutators methods for these two non-constant
attributes.
iii. Write a method area() to calculate the circle’s area by:
?????????? =??∗??????∗??????
This public method receives no parameters (using the class attributes)
and return a double.
c. These two new classes should be created in the same file together with the only
public class “Shape”. There’s a Shape.java file offered on Canvas, with a finished
main method. You can simply download it and write your “triangle” and “circle”
classes inside that same file. Your running result should be the same as the
following sample running.
d. Please remember to follow the data hiding rules!
Sample Running:
The first triangle's color is red
The area of first triangle is 50.0
The second triangle's information is blue 6.0 3.5
The second triangle is the same color as the first circle
The second circle is green. Its area is 12.56
classes to make the given main() run successfully.
a. Construct a new class named as “triangle” to store information of some right
triangle shapes. This class contains three parameters: double height, double
base, String color
i. Make two constructors for this class. One only initializes the object with a
String indicating this shape’s color. Another one initializes all three
attributes (height, base, color) for the new object. Check the offered
main() to order the parameters for the constructors.
ii. Write the accessors and mutators methods for these three attributes.
iii. Write a method area() to calculate the triangle’s area by:
???????????? =ℎ???ℎ?∗???? /2
This public method receives no parameters (using the class attributes)
and return a double.
b. Construct a new class named as “circle” to store information of some circle
shapes. This class contains three parameters: double radius, String color, final
static double PI = 3.14
i. Make two constructors for this class. One only initializes the object with a
String indicating this shape’s color. Another one initializes radius and
color for the new object. Check the offered main() to order the
parameters for the constructors.
ii. Write the accessors and mutators methods for these two non-constant
attributes.
iii. Write a method area() to calculate the circle’s area by:
?????????? =??∗??????∗??????
This public method receives no parameters (using the class attributes)
and return a double.
c. These two new classes should be created in the same file together with the only
public class “Shape”. There’s a Shape.java file offered on Canvas, with a finished
main method. You can simply download it and write your “triangle” and “circle”
classes inside that same file. Your running result should be the same as the
following sample running.
d. Please remember to follow the data hiding rules!
Sample Running:
The first triangle's color is red
The area of first triangle is 50.0
The second triangle's information is blue 6.0 3.5
The second triangle is the same color as the first circle
The second circle is green. Its area is 12.56