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:
|
|
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:
- Make a directory for
this lab.
- 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:
- Create a class named Throw.
- 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
- compile Throw and show the output
- Your Throw object should have the
“getters” – one to get
each of the fields of the object.
- compile Throw and show the output
- Your Throw object should have a toString() method.
- compile Throw and show the output
- 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)?
- compile Throw and show the output
3 Using a previously constructed object
- 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.
- Open your Tester class, and write your javadocs for the class.
- Do the following steps
in order:
- Roll your first Die object and print out the
result
- Roll your second Die object and print out the
result
- Create an instance of a
Throw object and print it
out
- Repeat steps 4,5 and 6 until you have filled an array with 5 Throw objects.
- Print out the values of
the firstThrow of each of your Throw objects.
Updated 09/24/08 (esa)