Home / Expert Answers / Computer Science / note-that-rectangle-and-diamond-are-specific-types-of-parallelograms-and-square-is-both-rectangle-pa612

(Solved): Note that Rectangle and diamond are specific types of parallelograms, and square is both rectangle ...



1. Consider the following class hierarchy:
Build a program to get the following information for each shape and print each sha

Note that Rectangle and diamond are specific types of parallelograms, and square is both rectangle and diamond, but because Java does not support multiple inheritances, we chose rectangle as the immediate parent.

A parallelogram can be uniquely identified by knowing the value of the two sides (the other two will be equal to these) and the angle between them.

A rectangle is a parallelogram where the angle is 90 degrees.
A diamond is a parallelogram where all the sides have equal values.
A square is a rectangle where all the sides have equal values.
The area and circumference of a parallelogram can be calculated as follow:

???????????????? = ????????????????1 ? ????????????????2 ? sin(????????????????????) ???????????????????????????????????????????????????? = 2 ? (????????????????1 + ????????????????2)

Create a class Parallelogram with three field variables as side1, side2 and angle with getters for all of them. Add to methods called getArea() and getCircumference(); returning the proper values in double. Also, override the toString() method so that the output matches the following screenshot.

The sinusoid function is available in Math package of java.util, but there is a consideration. It gets values in radians. But we’d like to get the values from the user in degrees. So create a private support method called convertToRadians() that receives the value of the angles in degrees and converts them to radians using the following formula for future use in the class. ????

???????????????????????????? = ???????????????????????????? ? 180

Create classes Rectangle, Diamond, and Square. Override the toString() method so that the output matches the screenshot.
In these children, there is no need to override methods such as getters and getArea(), and getCircumference(). (Why?)

The driver class shape is complete and should NOT be changed. Use it to test your codes.Parallelogram:
Sides: \( 5.0,4.0 \)
Angle between the sides in radians: \( 0.5235987755982988 \)
Area: \( 9.999999999999998 \

1. Consider the following class hierarchy: Build a program to get the following information for each shape and print each shape's information, area, and circumference. Parallelogram: Sides: \( 5.0,4.0 \) Angle between the sides in radians: \( 0.5235987755982988 \) Area: \( 9.999999999999998 \) Circumference: \( 18.0 \) Diamond: Side: \( 5.0 \) Angle: \( 0.6981317007977318 \) Area: \( 16.06969024216348 \) Circumference: \( 20.0 \) Square: Side: \( 2.3 \) Area: \( 5.289999999999999 \) Circumference: \( 9.2 \) Parallelogram: Sides: \( 2.4,6.8 \) Angle between the sides in radians: \( 0.4363323129985824 \) Area: \( 6.897130031608215 \) Circumference: \( 18.4 \) Rectangle: Sides: \( 5.0,4.6 \) Area: \( 23.0 \)


We have an Answer from Expert

View Expert Answer

Expert Answer


SOURCE CODE: import java.lang.Math; class Parallelogram{ //Base class for Diamond and Rectangle classes double side1; double side2; double angle; //Ge
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe