6.9 Programming Activity 1: Using while Loops
In this activity, you will work with a sentinel-controlled while loop, performing this activity:
Write a while loop to process the contents of a grocery cart and calculate the total price of the items. It is important to understand that, in this example, we do not know how many items are in the cart.
The framework will animate your code and display the current subtotal so that you can check the correctness of your code. The window will display the various Item objects moving down a conveyor belt toward a grocery bag. It will also display the unit price of the item and your current subtotal, as well as the correct subtotal.
For example, Figure 6.15 demonstrates the animation: We are currently ...
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.