Difference between revisions of "Cash Register"

From CompSciWiki
Jump to: navigation, search
 
Line 8: Line 8:
 
[[Image:Wiki_loops01.jpg|center]]<BR>
 
[[Image:Wiki_loops01.jpg|center]]<BR>
  
|Solution=The solution...
+
|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 infinite loop should be your starting point where numbers are asked and the running total is printed. That's your loop for an individual customer
 +
 
 +
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=
 +
<pre>
 +
 
 +
</pre>
  
 
}}
 
}}

Revision as of 10:00, 8 April 2010

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 infinite loop should be your starting point where numbers are asked and the running total is printed. That's your loop for an individual customer

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

SolutionCode goes here. Please DO NOT put your code in <pre> tags!

Back to the Program-A-Day homepage