The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Basic Problems

Posted by Matt Clark on February 20, 2002 at 10:54 AM

I have written a java program that emulates a vending machine. The machine dispenses items according to certain keys pressed.
The program has an option to quit, which displays a thankyou message, and also displays the total number of items sold.
I have no clue whatso-ever as tro how to perfrom this last operation. i'll post my code below.

class Vend3_2
{
public static void main(String[] args)
{



char group, response;
System.out.println("***ACME VEND INC***");
do
{
System.out.println(); // create blank line
System.out.println("[1] Get Gum ");
System.out.println("[2] Get Chocolate ");
System.out.println("[3] Get Popcorn ");
System.out.println("[4] Get Juice ");
System.out.println("[5] Display Total Sold ");
System.out.print("enter choice [1, 2, 3, 4, 5]: ");
response = EasyIn.getChar(); //get response
System.out.println(); // create blank line
switch (response) // process response
{
case '1': System.out.println("Here is your Gum ");break;
case '2': System.out.println("Here is your Chocolate ");break;
case '3': System.out.println("Here is your Popcorn ");break;
case '4': System.out.println("Here is your Juice ");break;
case '5': System.out.println("Thankyou for using ACME VEND! The number of items you brought today are being displayed now. ");break;
default: System.out.println("Error! Please choose options 1-5 only! ");break;
}
} while (response != '5'); // test for quit option
}
}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us