Starting from:

$24

Computer Science 221 Program 2

Learning
objectives:

·
Write a Java class.

·
Write multiple constructors.

·
Write a class that creates
objects of another class.

·
Make method calls to a Java
object.



Assignment:

Create a class called Box. This class has three properties, height, width, and depth (all doubles). It has two constructors. One has a single double
parameter, and is used when the box is a cube. The other has three parameters,
and is used when the box has different values for its dimensions. (Visualize a
shoe box.) The book discusses having multiple constructors for a single class
on p. 73.



The class Box has two methods. volume()
computes the volume of the box and returns it as a double. surfaceArea() computes the surface area of the box when it is closed (i.e., all
six faces are taken into account) and returns it as a double.



Create a second Java class called Store. Instantiate three boxes with different dimensions. Make at least
one box a cube and use the single-parameter constructor. Make at least one not
a cube. Display the volumes and surface areas of the three boxes. Be sure that
you create three separate boxes, i.e., not one box used three times.



Submission
instructions:

Upload the files
Box.java and Store.java to “Program 2”. Do not submit class files or any of the BlueJ
control files. Be sure to press the submit button.



Policies:

The policies
given on WebCT are in effect for this and all assignments.



You may submit
on WebCT multiple times, so there is no excuse for not submitting partial
solutions.

More products