In geometry, polygons are defined as plane (two-dimensional) and closed shapes that are formed by three or more straight lines joined with each other. Write a java program to develop an OOP solution presenting a regular polygon object. A regular polygon has a name, n number of sides with the same length. The perimeter of a regular polygon can be found by computing the total length of all n sides. A polygon can be a triangle that also has a height value. Polygon Triangle Create the following classes and interface: A. Interface Geometry includes a single method called perimeter () that returns a double value presenting the perimeter of a shape. B. Implement class Polygon as follows: • Include the required instance variables as described above, and a constructor method with arguments. Add two get methods to return number of sides and value of side length. • Implement the method perimeter() from the Geometry interface as the perimeter value of a polygon. • Implement area () method that returns value 0.0; • Override tostring() method to describe a polygon object; see Figure 2. C. Implement the Triangle subclass includes: • Its own instance variable(s), a constructor with argument, and get/set methods for each instance variable. • override area () method to compute and returns the area value of a triangle. Area = ;xbasexheight 2 Write the code for the tester class "PolygonTester.java" which has the following two methods: 1. readShapes () method that accepts a parameter holding a scanner object of file type and returns an arrayList of polygon objects. It reads each line from the input file, constructs and adds the corresponding a general polygon or a triangle type into the arrayList. Knowing that a triangle is a polygon with three sides; see Figure 1 for a sample input file, “shapes.txt".

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In geometry, polygons are defined as plane (two-dimensional) and closed shapes that are formed
by three or more straight lines joined with each other. Write a java program to develop an OOP
solution presenting a regular polygon object. A regular polygon has a name, n number of sides
with the same length. The perimeter of a regular polygon can be found by computing the total
length of all n sides. A polygon can be a triangle that also has a height value.
Create the following classes and interface:
A. Interface Geometry includes a single method called perimeter() that returns a double
value presenting the perimeter of a shape.
B. Implement class Polygon as follows:
 Include the required instance variables as described above, and a constructor method with
arguments. Add two get methods to return number of sides and value of side length.
 Implement the method perimeter() from the Geometry interface as the perimeter
value of a polygon.
 Implement area() method that returns value 0.0;
 Override toString() method to describe a polygon object; see Figure 2.
C. Implement the Triangle subclass includes:
 Its own instance variable(s), a constructor with argument, and get/set methods for each
instance variable.
 override area() method to compute and returns the area value of a triangle.
Write the code for the tester class “PolygonTester.java” which has the following two methods:
1. readShapes() method that accepts a parameter holding a scanner object of file type
and returns an arrayList of polygon objects. It reads each line from the input file, constructs
and adds the corresponding a general polygon or a triangle type into the arrayList. Knowing
that a triangle is a polygon with three sides; see Figure 1 for a sample input file,
“shapes.txt”. 

POLYGON
In geometry, polygons are defined as plane (two-dimensional) and closed shapes that are formed
by three or more straight lines joined with each other. Write a java program to develop an OOP
solution presenting a regular polygon object. A regular polygon has a name, n number of sides
with the same length. The perimeter of a regular polygon can be found by computing the total
length of all n sides. A polygon can be a triangle that also has a height value.
Polygon
Triangle
Create the following classes and interface:
A. Interface Geometry includes a single method called perimeter() that returns a double
value presenting the perimeter of a shape.
B. Implement class Polygon as follows:
Include the required instance variables as described above, and a constructor method with
arguments. Add two get methods to return number of sides and value of side length.
Implement the method perimeter() from the Geometry interface as the perimeter
value of a polygon.
• Implement area () method that returns value 0.0;
Override toString() method to describe a polygon object; see Figure 2.
C. Implement the Triangle subclass includes:
Its own instance variable(s), a constructor with argument, and get/set methods for each
instance variable.
override area () method to compute and returns the area value of a triangle.
1
Area = -xbasexheight
2
Write the code for the tester class "PolygonTester.java" which has the following two methods:
1. readShapes () method that accepts a parameter holding a scanner object of file type
and returns an arrayList of polygon objects. It reads each line from the input file, constructs
and adds the corresponding a general polygon or a triangle type into the arrayList. Knowing
that a triangle is a polygon with three sides; see Figure 1 for a sample input file,
“shapes.txt".
Transcribed Image Text:POLYGON In geometry, polygons are defined as plane (two-dimensional) and closed shapes that are formed by three or more straight lines joined with each other. Write a java program to develop an OOP solution presenting a regular polygon object. A regular polygon has a name, n number of sides with the same length. The perimeter of a regular polygon can be found by computing the total length of all n sides. A polygon can be a triangle that also has a height value. Polygon Triangle Create the following classes and interface: A. Interface Geometry includes a single method called perimeter() that returns a double value presenting the perimeter of a shape. B. Implement class Polygon as follows: Include the required instance variables as described above, and a constructor method with arguments. Add two get methods to return number of sides and value of side length. Implement the method perimeter() from the Geometry interface as the perimeter value of a polygon. • Implement area () method that returns value 0.0; Override toString() method to describe a polygon object; see Figure 2. C. Implement the Triangle subclass includes: Its own instance variable(s), a constructor with argument, and get/set methods for each instance variable. override area () method to compute and returns the area value of a triangle. 1 Area = -xbasexheight 2 Write the code for the tester class "PolygonTester.java" which has the following two methods: 1. readShapes () method that accepts a parameter holding a scanner object of file type and returns an arrayList of polygon objects. It reads each line from the input file, constructs and adds the corresponding a general polygon or a triangle type into the arrayList. Knowing that a triangle is a polygon with three sides; see Figure 1 for a sample input file, “shapes.txt".
2. Main () method that:
Asks a user for input file name and checks whether the file exist. Your code should
catch and handle FileNotFoundException.
Calls readShapes () method that reads from the input file polygon objects and adds
them in a single array list of polygon objects.
Sort the polygon objects the array list in ascending order based on their perimeter
values using the using Comparable interface. Hint: calling sort method for array list
by using Collections.sort(...).
After reading the whole input file, display the polygon's information sorted by their
perimeter values as shown in the sample output below, see Figure 2.
Sample input file: each line has information of a polygon shape in the following order: name,
number of sides, length of a side, and for triangle polygons the height value.
O shapes.txt - Notepad
File Edit Format View Help
Mirrors > 6 > 180.1
Sandwich > 3 > 6.3 > 9
Picture Frame > 4 > 11.5
Button > 5 > 1.3
Slice of Pizza > 3 > 15.6 > 17
Coins > 9 > 2
Arrow > 3 > 28.9 > 30
Toy House > 5 > 60.0
Figure 1: Sample input File "shapes.txt"
run:
Enter file name: shapes.txt
sorted by perimeter:
Polygons
sides
Perimeter
=====
Button
<5>
6.500cm
Coins
<9>
18.000cm
Sandwich
<3>
18.900cm
Picture Frame
<4>
46.000cm
Slice of Pizza
<3>
46.800cm
Arrow
<3>
86.700cm
Toy House
<5>
300.000cm
Mirrors
<6>
1080.600cm
BUILD SUCCESSFUL (total time: 2 seconds)
Figure 2: Sample output for "shapes.txt"
Transcribed Image Text:2. Main () method that: Asks a user for input file name and checks whether the file exist. Your code should catch and handle FileNotFoundException. Calls readShapes () method that reads from the input file polygon objects and adds them in a single array list of polygon objects. Sort the polygon objects the array list in ascending order based on their perimeter values using the using Comparable interface. Hint: calling sort method for array list by using Collections.sort(...). After reading the whole input file, display the polygon's information sorted by their perimeter values as shown in the sample output below, see Figure 2. Sample input file: each line has information of a polygon shape in the following order: name, number of sides, length of a side, and for triangle polygons the height value. O shapes.txt - Notepad File Edit Format View Help Mirrors > 6 > 180.1 Sandwich > 3 > 6.3 > 9 Picture Frame > 4 > 11.5 Button > 5 > 1.3 Slice of Pizza > 3 > 15.6 > 17 Coins > 9 > 2 Arrow > 3 > 28.9 > 30 Toy House > 5 > 60.0 Figure 1: Sample input File "shapes.txt" run: Enter file name: shapes.txt sorted by perimeter: Polygons sides Perimeter ===== Button <5> 6.500cm Coins <9> 18.000cm Sandwich <3> 18.900cm Picture Frame <4> 46.000cm Slice of Pizza <3> 46.800cm Arrow <3> 86.700cm Toy House <5> 300.000cm Mirrors <6> 1080.600cm BUILD SUCCESSFUL (total time: 2 seconds) Figure 2: Sample output for "shapes.txt"
Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY