Sorry!
I'd like the code to do this:
ask user a question
user answers yes, 1 is added to customer count (customer variable)
user has to answer yes each time for 1 to be added to count
once customer reaches 100, message dialog comes up saying that customer won a book
You know what I'm sayin'?
--- Update ---
Originally Posted by
Zaphod_b
If you want to wait again, then call the method again each time.
Pseudo-code could go something like the following:
Declare integer variables numCustomers and maxCustomers.
Initialize customer to zero and maxCustomers to whatever...
Repeat the following loop as long as numCustomers is less than maxCustomers.
BEGIN LOOP
Prompt user with showConfirmDialog
IF (The answer from showConfirmDialog is equal to CANCEL_OPTION) THEN
Break out of the loop.
END IF
IF (The answer from showConfirmDialog is equal to YES_OPTION) THEN
Increment numCustomers.
Do whatever else you need to do when user clicks "Yes."
END IF
END LOOP
Cheers!
Z
Ahh.. like this?
import javax.swing.JOptionPane;
public class CustomerCounter {
public static void main(String[] args) {
int numCustomers = 0;
int maxCustomers = 100;
while (numCustomers < maxCustomers){
int answer = JOptionPane.showConfirmDialog(null, "Has a customer entered the store?");
if (answer == JOptionPane.CANCEL_OPTION){
System.exit(0);
}
if (answer == JOptionPane.YES_OPTION){
numCustomers++;
}
System.out.println("There are " + numCustomers + " customers in the store.");
if (numCustomers == 100){
System.out.println("This customer wins a free book! Yay!");
}
}
}
}
Here's a good question.. let's say, instead of System.out.println("This customer wins a free book! etc etc) I'd like a message dialog to come up displaying a picture of a book. How would I do that?
UPDATE: How do I "break" the loop? Is there a way to keep the program running, so that even if the user clicks on Cancel, the customer count will remain intact? As in, I won't have to run the program again and start the customer count back at 0?