Question: Lab 10-1: Creating a Programmer-Defined Class in Java In this lab, you will create a programmer-defined class and then use it in a Java program.
Lab 10-1: Creating a Programmer-Defined Class in Java In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectangle objects and find their area and perimeter. U the Circle class that you worked with in Exercise 10-1 as a guide. 1. Open the class file named Rectangle. java using Notepad or the text editor of 2. In the Rectangle class, create two private attributes named 1ength and width. Both length and width should be data type double. 3. Write public set methods to set the values for 1ength and width 4. Write public get methods to retrieve the values for length and width. 5. Write apublic calculateAreaO method and a public calculatePerimeterO method to calculate and return the area of the rectangle and the perimeter of the rectangle Save this class file, Rectangle.java, in a directory of your choice, and then open the file named MyRectangleClassProgram.java. In the MyRectangleClassProgram class, create two Rectangle objects named rectanglel and rectangle2 using the default constructor as you saw in EmployeeWages.java. 6. 7. Set the length of rectangle1 to 10.0 and the width to 5.0. Set the length of rectangle2 to 7.0 and the width to 3.0. Print the value of rectanglel's perimeter and area, and then print the value of rectangle2's perimeter and area. 8. 9. 10. Save MyRectangleClassProgram.java in the same directory as Rectangle.java. 11. Compile the source code file MyRectangleclassProgram.java. 12. Execute the program. 13. Record the output below
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
