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 YourlastnameLab3. A text editor window should pop up, showing the content of the java main class file titled YourlastnameLab3.java. 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.3. Create a Java class file for a Polygon class.4. 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.5. 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: 56. Create a Java class file for a RegularPolygon class.7. 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 double).(i) 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.8. Add code to the main method of your main class to do the following:(n) Create a RegularPolygon object and display it.(o) 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: 4Testing RegularPolygon constructorNumber of sides: 5Side length: 1.0Perimeter: 5.0Testing side length mutatorNumber of sides: 5Side length: 2.0Perimeter: 10.09. Create a Java class file for a RegularTriangle class.10. 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 double).(r) 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 it.(v) Override the toString method to add information about the height and area.11. Add code to the main method of your main class to do the following:(w) Create a RegularTriangle object and display it.(x) 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: 4Testing RegularPolygon constructor Number of sides: 5Side length: 1.0Perimeter: 5.0Testing side length mutator Number of sides: 5Side length: 2.0Perimeter: 10.0Testing RegularTriangle constructor Number of sides: 3Side length: 4.0Perimeter: 12.0Height: 3.4641016151377544Area: 6.928203230275509Testing height mutator Number of sides: 3Side length: 3.464101615137755Perimeter: 10.392304845413264Height: 3.0Area: 5.196152422706632Testing side length mutator Number of sides: 3Side length: 4.0Perimeter: 12.0Height: 3.4641016151377544Area: 6.928203230275509

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!