Question: Need guidance In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectangle

Need guidance

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.

Instructions

Make sure the class file named Rectangle.java is open.

In the Rectangle class, create two private attributes named length and width. Both length and width should be data type double.

Write public set methods to set the values for length and width.

Write public get methods to retrieve the values for length and width.

Write a public calculateArea() method and a public calculatePerimeter() method to calculate and return the area of the rectangle and the perimeter of the rectangle.

Open the file named MyRectangleClassProgram.java.

In the MyRectangleClassProgram class, create two Rectangle objects named rectangle1 and rectangle2.

Set the length of rectangle1 to 10.0 and the width to 5.0. Set the length of ectangle2 to 7.0 and the width to 3.0.

Print the value of rectangle1s perimeter and area, and then print the value of rectangle2s perimeter and area.

Execute the program.

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 Databases Questions!