0% found this document useful (0 votes)
19 views2 pages

Lab 07

Uploaded by

mert
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Lab 07

Uploaded by

mert
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Computer Engineering Department

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:

Task 1 (80 points)

Write an abstract class Shape with the following properties:

 An instance variable shapeName of type String

 An abstract method volume()

 A toString method that returns the name of the shape


The file Sphere.java contains a class for a sphere which is a descendant of Shape. A sphere has a radius
and its volume is given by the formula (4/3)*PI*radius3. Define similar classes for a square prism and a
cylinder. Both the SquarePrism class and the Cylinder class are descendants of the Shape class. A
2
square prism is defined by its base side length (a) and height and its volume is a *height. A cylinder is
defined by a radius and height and its volume is PI* radius2 *height. Define the toString method in a way
similar to that for the Sphere class.

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.)

Task 2 (20 points)

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.

You might also like