Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Develop a class called Rectangle with the following members: Public Class constants DEFAULT _ WIDTH with value of 5 Public Class constants DEFAULT _ HEIGHTS
Develop a class called Rectangle with the following members:
Public Class constants DEFAULTWIDTH with value of
Public Class constants DEFAULTHEIGHTS with value of
Public Instance Variables width, length, area
Public method initRect that takes as input a width and height and sets the corresponding member values to these valuesthe method returns nothing
Public method computeArea that computes area and saves it as the variable area
Public method getArea that returns the area of the object
Public method setWidth that sets the width of the object to the corresponding value supplied by the input parameter
Public method setLength that sets the length of the object to the corresponding value supplied by the input parameter
Provide the body of a main program that would perform the following:
Creates an object of the class Rectangle called r
Initializes the object with a value of for width and the content of the variable y as length
Computes the area of r
Gets the area of the object and displays it to the user via the System.out command
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started