Java Reference
In-Depth Information
case
3:
sellProduct(gum, cashRegister);
break
;
case
4:
sellProduct(cookies, cashRegister);
break
;
default
:
System.out.println("Invalid Selection");
}
//end switch
showSelection();
//Step 6b
choice = console.nextInt();
//Step 6c
}
//end while
}
//end main
MAIN PROGRAM LISTING
//Program: Candy Machine
import
java.util.*;
public class
CandyMachine
{
static
Scanner console =
new
Scanner(System.in);
//Place the definition of the method main as given above here.
//Place the definition of the method showSelection as
//given above here.
//Place the definition of the method sellProduct as
//given above here.
}
Sample Run: (In this sample run, the user input is shaded.)
*** Welcome to Shelly's Candy Shop ***
To select an item, enter
1 for Candy
2 for Chips
3 for Gum
4 for Cookies
9 to exit
1
Please deposit 50 cents: 50
Collect your item at the bottom and enjoy.
Search WWH ::
Custom Search