Question: Start with a working Point class. Refer to the Point program created for Lab # 1 : 2 . Write a new Rectangle class, a
Start with a working Point class. Refer to the Point program created for Lab #:
Write a new Rectangle class, a subclass of the Point class.
a Add width and length variables to the new class.
b Add constructors
i a default Rectanglewhere width length
ii a argument constructor Rectanglewidth length
iii. use the Super default constructor for the x y values
c Add get and set methods as needed to support your new instance variables.
d Add a method called area that:
i Calculates the area of a Rectangle object: Area length width
ii returns the Area of a Rectangle object
iii. Do not store the area in a member variable.
e Override the toString method found in class Point to display and label all of the characteristics
instance variables of a Rectangle object. Do not forget to include the original point instance
variables by using the super.toString
Write a new Box class, a subclass of the Rectangle class.
a Add height as a new variable in this class
b Add constructors
i a default Box where width length height
ii a argument constructor Boxheight
iii. use the Super default constructor for the x y width, height values
c Add get and set methods as needed.
d Override the area method inherited from the Rectangle class to calculate the outside face area
sides of a Box object.
i Calculates: Area length width width height length height
ii returns the area of a Rectangle object
iii. Do not store the area in a member variable.
e Add a method called volume that:
i Calculates the volume of a Box object: Volume length width height.
ii returns the volume of a Box object
Lab Advanced Java
Inheritance
Rev. : PM
iii. Do not store the volume in a member variable.
f Override the toString method inherited from class Rectangle to display and label all of the
characteristics instance variables of a Box object. Do not forget to include the original point
and rectangle instance variables by using the super.toString
Write an executable client class called ShapesTester a separate program that uses the Point,
Rectangle and Box classes.
a Print your name, Lab number, and date as the first three lines of output. Hardcode the date...do
not use the system date.
b Create two objects of type Point,
i point Point
ii point Point
c Create two objects of type Rectangle
i rectangle Rectangle
ii rectangle Rectangle
d Create two objects of type Box.
i box Box
ii box Box
e Execute the area methods for all objects of type Rectangle and Box. The area should be
printed from the ShapesTester class. Remember the area is being returned to the client.
f Execute the volume and area methods for all objects of type Box. The volume should be
printed from the Shapes class. Remember the volume is being returned to the client.
g Change the width of box to
h Execute the volume and area methods for box The volume should be printed from the
ShapesTester class. Remember the volume is being returned to the client.
i Execute the toString method for all objects.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
