Question: Create a new project called YourlastnameLab 3 . A text editor window should pop up , showing the content of the java main class file
Create a new project called YourlastnameLab A text editor window should pop up showing the content of the java main class file titled YourlastnameLabjava. The main class file is automatically created when you create a new project and displays template source code from NetBeans. In the main function of your main class, remove the line that prints Hello World to the output screen and save the file Create a Java class file for a Polygon class Implement the Polygon class.a Add a private instance variable representing the number of sides in the polygon.b Add a constructor that takes a single argument and uses it to initialize the number of sides. If the value of the argument is less than three, display an error message and exit the program.c Add an accessor method for the number of sides.d Override the toString method of the Object class to return a String containing the number of sides Add code to the main method of your main class to do the following:e Create a Polygon object.f Pass the object to System.out.println to display it Run the program to make sure it works. The output should look something like this: Testing Polygon constructorNumber of sides: Create a Java class file for a RegularPolygon class Implement the RegularPolygon class.g Modify the class header to make RegularPolygon a subclass of Polygon.h Add a private instance variable to represent the length of a side a doublei Add a constructor that takes an int and a double and uses them to initialize the private instance variables. If the length of the side is less than or equal to zero, display an error message and exit the program.j Add an accessor method and a mutator method for the length of a side.k Move the code from the constructor that does the input validation and initialization of the length of a side to the mutator method. Replace the constructor code you just moved with a call to the mutator.l Add a method called getPerimeter that calculates the perimeter of the polygon. Remember that all of the sides of a regular polygon have the same length.m Override the toString method from the Polygon class to include the side length and perimeter along with the number of sides. Use the toString method from the base class to construct the first part of the string Add code to the main method of your main class to do the following:n Create a RegularPolygon object and display ito Call the side length mutator, and display the object again. Run the program to make sure it works. The output should look something like this: Testing Polygon constructorNumber of sides: Testing RegularPolygon constructorNumber of sides: Side length: Perimeter: Testing side length mutatorNumber of sides: Side length: Perimeter: Create a Java class file for a RegularTriangle class Implement the RegularTriangle class.p Modify the class header to make RegularTriangle a subclass of RegularPolygon.q Add a private instance variable for the height of the triangle a doubler Add a constructor that takes a double representing the length of a side and uses the RegularPolygon constructor to initialize the number of sides and the side length. You do not need to initialize the height you will see why in the next step.s Override the side length mutator so it calls the RegularPolygon mutator to initialize the side length, then sets the height to This will take care of initializing the height since the constructor calls the RegularPolygon constructor, which calls this version of the side length mutator.t Write an accessor method and a mutator method for the height. The mutator should display an error message and exit the program if the value provided is less than or equal to zero. It should also set the side length to u Write a method called getArea that calculates the area of the triangle using the formula and returns itv Override the toString method to add information about the height and area Add code to the main method of your main class to do the following:w Create a RegularTriangle object and display itx Call the height mutator, and display the object.y Call the side length mutator, and display the object. Run the program to make sure it works. The output should look something like this: Testing Polygon constructorNumber of sides: Testing RegularPolygon constructor Number of sides: Side length: Perimeter: Testing side length mutator Number of sides: Side length: Perimeter: Testing RegularTriangle constructor Number of sides: Side length: Perimeter: Height: Area: Testing height mutator Number of sides: Side length: Perimeter: Height: Area: Testing side length mutator Number of sides: Side length: Perimeter: Height: Area:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
