For this lab, you will create a simple class hierarchy using inheritance.
-
Create a Java class
Furniture. Each piece of furniture has a cost (an integer number of cents, so a cost of 999 represents $9.99), and a description (aString).Create a
toStringmethod that outputs information about a piece of furniture in the form:Coffee Table ($67.99)Hint:
return String.format("%s ($%.2f)", …); -
Create a class
Chairthat is a subclass ofFurniturethat adds a boolean to keep track of whether or not the chair is padded. Add an appropriate constructor that sets the three member variables.Do not create a
toStringmethod: use the one inherited fromFurniture. -
Create a class
Tablethat is a subclass ofFurniture. Each table will have a width and length (in meters), in addition to the properties of all furniture.Create a constructor that sets the member variables of a
Table. Override thetoStringmethod so an instance is printed in this form:Coffee Table [2.3 x 1.5 m] ($67.99) -
Create a class
FurnTestthat contains amainfunction. In themainfunction, create anArrayListofFurnitureobjects. Add to it some objects of each type (Chair,Table).Then, iterate through the list and output each one (with
System.out.println), creating output like this:Kitchen Chair ($59.99)
Kitchen Chair ($59.99)
Kitchen Chair ($59.99)
Kitchen Chair ($59.99)
Kitchen Table [2.3 x 1.5 m] ($129.50) -
Create a text file named
time.txt. In it, indicate how long it took you to complete this lab exercise.
When you're done, create a ZIP file containing all of the files you created for this lab and submit it with the submission server.