Advanced Programming - CS239
LAB 7:
DEVELOPING A LENGTH CLASS – to be continued
Getting
Ready: Before going any further you should:
Part I: This part of the lab is concerned with
"stubbing-out" a
Length class and creating a driver for testing that
class. The driver below can be used to test your Length class.
* A
driver that can be used to test the Length class * *
@author Prof. David Bernstein, James Madison University *
@version 1.0 *
@author Professor Elizabeth Adams, James Madison University *
@version 1.1 *
@author Professor Nancy Harris, James Madison University *
@version 1.2 */ public
class Driver { /** * The entry point of the application * * @param args The command line arguments */ public static void main(String[] args) { Length billsHeight, growth,
mikesHeight; //
test 2 paramter constructor mikesHeight = new Length(5, 5); billsHeight = new Length(5, 5); // test toString System.out.println("Age 12:
"); printSummary("Mike",
mikesHeight, "Bill", billsHeight); // get ready to test changeLength growth = new Length(); mikesHeight.changeBy(growth); //change length for both persons growth = new Length(0, 4); billsHeight.changeBy(growth); System.out.println("Age 16:
"); printSummary("Mike",
mikesHeight, "Bill", billsHeight); //
and again growth = new Length(1, 1); mikesHeight.changeBy(growth); growth = new Length(0,10); billsHeight.changeBy(growth); System.out.println("Age 20:
"); printSummary("Mike",
mikesHeight, "Bill", billsHeight); // test three parameter constructor (they
begin to lose height) growth = new Length(0,1,false); billsHeight.changeBy(growth); System.out.println("Age 70:
"); printSummary("Mike",
mikesHeight, "Bill", billsHeight); } // Normally we would want the main method
to be the only thing in a class. // However, this is simply a test
class. So the printSummary which // supports the testing will be permitted
here. // This Driver will not be used when
Length is fully tested. /** * Print summary information for two
Length objects * * @param name1 The name for the first
Length * @param length1 The first Length object * @param name2 The name for the second
Length * @param length2 The second Length object */ private static void printSummary(String
name1, Length length1, String
name2, Length length2) { System.out.println(" " +
name1 + ": " + length1); // Uses toString System.out.println(" " +
name2 + ": " + length2); // Uses toString //
tests the equals length and uses its result to print a message. if (length1.equals(length2)) { System.out.println(" == SAME
=="); } else { System.out.println("
== DIFFERENT =="); } System.out.println("\n"); } } |
This Driver.java program is strictly used to test your Length class methods and is not to be altered in Part 1.
Stubbing out means that you will provide attributes and methods. For each method, you will provide the header, an appropriate return statement that will return a value of the required type and all documentation to describe the operation of each method. No actual code (other than the attribute declarations and headers) should be included in the stub. You will use the stubbed-out class to begin your development step.
The
Length class stubs must contain:
Note: The number of inches and feet in a Length must always be non-negative. In addition, the number of inches must never
be 12 or greater. You should include
code or comments for this wherever a length value is changed.
|
Stop!!!
Print out your Length.java program and turn
it in BEFORE CONTUING ON WITH THIS LAB. You will continue with this same program, for the later steps,
but be sure to turn in this initial step first. This must be completed and submitted before the end of the lab.
NOTE: Your Driver.java program should only have in
it method headers , attribute declarations, javadocs, internal comments (i.e. the elements described above).
Get Professor Adams to
initial this box before continuing with the steps on the next page.
|
Part II: This part of
the lab is concerned with developing and testing the Length class.
|
|
Steps 1-6 of Part 2 must be turned in
by Tuesday Feb 8 but you may turn it all
in.
|
|