Java Reference
In-Depth Information
System.out.print("Line 30: After "
+ "incrementing the time by "
+ "one second, myClock: ");
//Line 30
myClock.printTime();
//Line 31
System.out.println();
//Line 32
yourClock.makeCopy(myClock);
//Line 33
System.out.print("Line 34: After copying "
+ "myClock into yourClock, "
+ "yourClock: ");
//Line 34
yourClock.printTime();
//Line 35
System.out.println();
//Line 36
} //end main
}
Sample Run: (In this sample run, the user input is shaded.)
Line 6: myClock: 05:04:30
Line 9: yourClock: 00:00:00
Line 13: After setting the time, yourClock: 05:45:16
Line 19: The two times are not equal.
Line 20: Enter hours, minutes, and seconds: 11 22 59
Line 26: New time of myClock: 11:22:59
Line 30: After incrementing the time by one second, myClock: 11:23:00
Line 34: After copying myClock into yourClock, yourClock: 11:23:00
A walk-through of the preceding program is left as an exercise for you.
EXAMPLE 8-3
Consider the following class definition:
public class Inventory
{
private String name;
private int itemNum;
private double price;
private int unitsInStock;
public Inventory()
//Constructor 1
{
name = "";
itemNum = -1;
price = 0.0;
unitsInStock = 0;
}
 
Search WWH ::




Custom Search