You are on page 1of 2

Object Oriented Programming Essentials

Tutorial 9 – Writing Classes

 Create a folder called Tutorial 9 to save all files.

Cylinder

- diameter: double
- height: int
+ Cylinder (d: double, h: int)

+ area (): double

+ volume (): double

+ details(): void

Information for the Cylinder class:

Constructor: Sets the diameter and height of the Cylinder.

Area Cylinder: π r2 x 2 + π d x h

Volume Cylinder: π r2 x h

details(): prints the attributes and the volume of the


Cylinder.

1. Download the Cylinder.java file from CANVAS and complete the class by doing the tasks

given. [Note: It must match the class diagram given above.]


2. Cylindrical oil tanks are used to store crude oil and there are currently 3 large tanks in

use. The dimensions of the tanks are [diameter: 20m, height: 15m],

[diameter: 30m, height: 20m] and [diameter: 42m, height:

18m]. Write a program called CreateTanks that uses the Cylinder object to map each

tank by doing the following:

a. Create Cylinder objects called tank1, tank2 and tank3 for each of the crude

oil tanks.

b. Given that the tanks are filled with crude oil print total volume of oil being

stored.

1
c. If of tank2 is emptied, how much crude oil remains in the tank.
3

d. Whenever a tank is empty the inside walls must be painted. If tank1 is empty

what surface area would be painted?

e. When routine maintenance is done the details of the tanks must be known. Print

the details of each tank.

You might also like