Cash Register

From CompSciWiki
Jump to: navigation, search

Back to the Program-A-Day homepage

Problem

We need an adding machine! Your goal: Allow the cashier to enter prices. When done with one customer, entering a blank number prints the total the customer owes. Typing 'done' will exit the program.

 

Getting Started

Wiki loops01.jpg

Solution

Simple as pie really. You should already know about JOptionPane wonders for entering data, you just need to convert that text to numbers, and add them. An initial loop should be your starting point where numbers are asked and the running total is printed. That's your loop for an individual customer. If nothing is submitted, that's your clue they want to exit the loop.

The next step is to introduce an outer loop so we can deal with more than one customer per program run. Zeroing counts and printing the final total should be a cakewalk for a superstar programmer such as yourself.

Code

Solution Code

Back to the Program-A-Day homepage