Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objects and Constructors Define a class of rectangles. Design a class named Rect

ID: 3726327 • Letter: O

Question

Objects and Constructors Define a class of rectangles. Design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1.0 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with a specified width and height A method named getArea0 that returns the area of a rectangle. > A method named getPerimeterO that returns the perimeter. Requirements: 1. Draw the UML of the Rectangle class. 2. Implement this class. 3. Write a test program with a main method that should do the following tasks: . Create the first rectangle using the no-arg constructor Create a second rectangle using the constructor's arguments to set the width to 4.0 and the height to 40.0. Print out the area of the first rectangle. Print out the perimeter of the second rectangle. Please note: You must finish this work by the end of the lab period. If you do not finish, please just submit what you have at the end of the lab. Submission: Submit the UML in a word or PDF file and program in a java file in folio using the dropbox folder Lab 9.

Explanation / Answer

When you define a new object of a class, its functions and variables dont change.

Class rectangle has 2 variables width and height, but when you defined the object rect2, you have used newWidth and newHeight,which doesnt exist. Therefore error occurs.

To get rid of the error use rect2.width instead of rect2.newWidth, and rect2.height instead of rect2.newHeight