Homework 9

1. Circle class (10 points)

Define and implement a class called Circle which has the following instance variable, constructors and methods.

Instance Variable:

Constructors:

Methods:

NOTES:

  1. Both the getArea and getCircumference methods must use the respective static methods to calculate the area and circumference.
  2. You must use the value of p stored in the Math class (i.e. Math.PI).

2. Cylinder class (10 points)

Define and implement a class called Cylinder which has the following instance variables, constructors and methods.

Instance Variables:

Constructors:

Methods:

NOTES:

  1. The diameter of the Cylinder object should be stored (as a radius) in the circle instance variable, which is a Circle object!.
  2. Utilize the methods available with the Circle object to make implementing the methods for the Cylinder class easier. Most of the methods should be implemented in one line!

3. Pipe class (10 points)

Define and implement a class called Pipe which is derived from the Cylinder class and has the following instance variable, constructor and methods.

Instance Variable:

Constructor:

Methods:

NOTES:

  1. Most, if not all, of the constructor and method implementations should be one line. Take advantage of the inherited methods and parent constructors when applicable.
  2. You must override the getSurfaceArea method inherited from the Cylinder class, since the surface area of a pipe is differnt than that of a cylinder (i.e. a pipe is a hollow cylinder).
  3. Assume the thickness of the pipe is infintesimally small.

4. PipeTest class (5 points)

Define and implement a class called PipeTest which demonstrates the complete functionality of only the Pipe class.

NOTES:

  1. To demonstrate the functionality of the toString method, simply pass the Pipe object to the System.out.println method. This will result in the toString method of the passed Pipe object being called and it's return value being printed to the screen.