JamesMadisonUniversity

Computer Science Department


CS 239 Lab 10 : More Objects


Objectives:

The student will:

  • create a new object
  • use objects from earlier lab
  • build an array of objects
  • use a testing program to unit test each component of the system.

Background:

  • you have created and worked with objects this semester
  • you have created arrays and worked with them last semester

New Terms:

  • none

Materials:

There are no materials for this lab.  All work will be done from scratch. You will upload all of your files to the Blackboard Assignment for this lab and print out the worksheet for this lab..  .

Acknowledgment

Lab by Elizabeth Adams


1 Getting Ready:

Before going any further you should:

  1. Make a directory for this lab.
  2. Create a file called Tester.java which will contain a single main method that will be used to exercise each component of the lab and demonstrate that you have done that step correctly.

2 Create a new Class:

  1. Create a class named Throw. 
  2. A Throw object has 3 fields:  firstThrow, secondThrow and point which should be set by an explicit value constructor.  point is the sum of  firstThrow and secondThrow
  3. compile Throw and show the output
  4. Your Throw object should have the “getters” – one to get  each of the fields of the object.
  5. compile Throw and show the output
  6. Your Throw object should have a toString() method.
  7. compile Throw and show the output
  8. Your Throw object should have an equals method. This method should test  two Throw objects to see if they are equal..  (What does their being equal mean)?
  9. compile Throw  and show the output

 3 Using a previously constructed object

  1. You will be using your previously created Die class in this Tester. Your main program will roll two Die objects, and use the results to create a Throw object which you will store in an array of Throw objects.
  2. Open your Tester class, and write your javadocs for the class.
  3. Do the following steps in order:
  4. Roll your first Die object and print out the result
  5. Roll your second Die object and print out the result
  6. Create an instance of a Throw object and print it out
  7. Repeat steps 4,5 and 6 until you have filled an array with 5 Throw objects. 
  8. Print out the values of the firstThrow of each of your Throw objects.

Updated 09/24/08 (esa)