
354 CHAPTER 6 Flow of Control,Part 2: Looping
■
After you get a new Item, you can “scan” the item to get its price by
calling the getPrice method of the Item class. The getPrice method
has this API:
double getPrice( )
Thus, you would get the next item, then get its price using code like
the following:
Item newItem;
double price;
newItem = getNext( );
price = newItem.getPrice( );
When you have finished writing the code for the checkout method, compile
and run the application from the Cashier class. When the application fin-
ishes executing, verify that your code is correct by:
■
checking that your subtotal matches the correct subtotal displayed
■
checking that ...