Tuesday, November 22, 2011

Homework 11 - Cube.java, CubeTest.java

You are to create a class Cube.

Cube contains:
  • One double data field named side
  • A double constant named DEFAULT_SIDE which is equal to 1.0
  • A zero-argument constructor which sets side to the default value
  • A one-argument constructor which sets side to the value passed, unless that value is less than or equal to zero
    (requires error trapping)
  • Methods to get and set side
    (the set method requires error trapping)
  • A method named getVolume which returns the volume of the Cube
  • A method named getTotalSurfaceArea which returns the total surface area of the Cube
  • A method named getSingleFaceSurfaceArea which returns the surface area of only one face of the Cube
  • A method named displayCube which displays the Cube's parameters: side, volume, total surface area, and surface area of a single face
    (format the output appropriately, including strings telling the user what exactly is being displayed)
Write a console application test program named CubeTest that creates an array of Cube objects. There should be three objects in the array. The sides should be set using a for loop that runs from 0 to the length of the array. Write a method in CubeTest which displays each Cube in the array.

Both files should be saved to the same directory: no hard coding of paths nor file names.

Sample Output
Here is a screenshot of my code running.


Cubism output


Due Date:
Monday, December 5th, 8:00am