Java Reference
In-Depth Information
{
int firstClassStamps = (int) (money /
FIRST_CLASS_STAMP_PRICE);
money = money - firstClassStamps *
FIRST_CLASS_STAMP_PRICE;
return firstClassStamps;
}
public int givePennyStamps()
{
int pennyStamps = (int) Math.round(100
* money);
money = 0;
return pennyStamps;
}
public static final double
FIRST_CLASS_STAMP_PRICE = 0.39;
private double money;
}
Step 6 Test your class.
Run a test program (or use an integrated environment such as BlueJ) to verify that
the values that your class computes are the same values that you computed by
hand. In our example, try the statements
StampMachine machine = new StampMachine();
machine.insert(1);
System.out.print("First class stamps: ");
System.out.println(machi
ne.giveFirstClassStamps());
System.out.println("Expected: 2");
System.out.print("Penny stamps: ");
System.out.println (machine.givePennyStamps());
System.out.println("Expected: 22);
Check that the result is
First class stamps: 2
Expected: 2
Penny stamps: 22
Expected: 22
157
Search WWH ::




Custom Search