CST2641 Advanced Java I
Lab Week 2


Exercises

Exercise 5.1

I am providing you with a Java application that has a class called Square.

Write a class Cube1 which makes use of the Square class, has a height attribute and has a method which returns the volume of the cube.  This class should NOT use inheritance.  You should define a suitable constructor method for this class.  Add some draw.Strings to test your results.

Write a class Cube2 which inherits (extends) from the Square class, adds a height attribute and adds a method which returns the volume of the cube.  You should define a suitable constructor method for this class.  Add some draw.Strings to test your results.

Write a class Rectangle which inherits from the Square class, adds a variable for the length of the rectangle, and overrides the perimeter and area methods in the Square class.  You should change the width attribute of the Square class from private to private protected.

Here is the Java application source code:  Perimeter.java

Screen snapshot of the original program.

Here is the finished result.  This is a standalone program (cannot be run in a browser).
Perimeter.class
Square.class

Cube1.class
Cube2.class
Rectangle.class