Create aJava GUI program that calculates the area, and perimeter of arectangle o
ID: 3609875 • Letter: C
Question
Create aJava GUI program that calculates the area, and perimeter of arectangle or triangle, or the area and circumference acircle. Your program will read a file that contains 4 spaceseparated fields. The input file name should be passed as acommand line argument.The first field is a string that specifiesthe shape. The remaining three fields are integer fields andare described below.
Shape -String
IntegerField #1
IntegerField #2
IntegerField #3
Circle
Radius
0
0
Rectangle
Length
Width
0
Triangle
Side A
Side B
Side C
Yourprogram should read the first line of the input file and displaythe name of the shape, the three integer fields, the area, and theperimeter or circumference of the shape based on the values of thethree integer fields. There should be a Nextbutton that when pressed will read the next line of the input fileand display the next shape, area, etc. in the input file.
The area of a triangle can be calculated given the three sidesof a triangle (a, b, and c) using the following formula:
Area of Triangle = SQRT(s(s-a)(s-b)(s-c))
where s = perimeter/2.
SampleInput File
Circle 5 0 0
Rectangle 5 6 0
Triangle 4 4 5
End 0 0 0
Program Requirements:
Yourprogram must have a super class named Shape, andthree subclasses (Circle, Triangle, andRectangle) that extend Shape.
Each ofyour three subclasses must have the following value returningmethods: calcArea, equals andtoString. Each of your subclasses shouldhave private data members that store the dimensions of the shape(dimensions are read from the input file). Your Rectangle and Trianglesubclasses must also include a value returning methodcalcPerimeter. The Circleclass must include a calcCircumference method. Your programmust use these subclass methods in order to calculate the area,perimeter and circumference. Your program should NOTinstantiate the Shape class.
Theequals method should take one parameter (object ofit’s class type) and return true if the two objects datamembers are identical, otherwise it should return false.
ThetoString method should return the type of objectand it’s dimensions.
Example: The Circle toString should return a stringcontaining “Circle with a radius equal to 2”.
Shape -String
IntegerField #1
IntegerField #2
IntegerField #3
Circle
Radius
0
0
Rectangle
Length
Width
0
Triangle
Side A
Side B
Side C
Explanation / Answer
class Rectangle
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.