Lab 07
Lab 07
Lab Assignment 07
2020 – 2021 Spring, CMPE 211 Fundamentals of Programming II
PAINTING SOLIDS
In this lab, you will develop a class hierarchy of shapes and write a program that computes the amount of
paint needed to paint different objects. The hierarchy will consist of a parent class Shape with three
derived classes - Sphere, SquarePrism, and Cylinder. For the purposes of this exercise, the only
attribute a shape will have is a name and the method of interest will be one that computes the volume of
the shape. You are asked to do the following tasks:
The file Paint.java contains a class for a type of paint (which has a “coverage” and a method to compute
the amount of paint needed to paint a shape). Correct the return statement in the amount method so the
correct amount will be returned. Use the fact that the amount of paint needed is the volume of the shape
divided by the coverage for the paint. (NOTE: Leave the print statement - it is there for illustration
purposes, so you can see the method operating on different types of Shape objects.)
The file PaintThings.java contains a program that computes the amount of paint needed to paint
various shapes. A paint object has been instantiated. Add the following to complete the program:
a. Instantiate the three shape objects: deck to be a square prism of base side length 10 and height 25,
bigBall to be a sphere of radius 20, and tank to be a cylinder of radius 5 and height 15.
b. Make the appropriate method calls to assign the correct values to the three amount variables.
1
Computer Engineering Department
c. Run the program and test it. You should see polymorphism in action as the amount method
computes the amount of paint for various shapes.
You can see expected program run (demo) from the link below:
https://asciinema.org/a/FAz6VFVUuBdYvtpg9aB6Aakil
Submission
You need to implement all the required tasks above and upload your Java source files (.java) as a single Zip
file into the available Moodle submission.