Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Created with IntelliJ IDEA.
- * User: Marcello Missiroli prof.missiroli@gmail.com
- * Date: 24/11/13
- * Time: 14.35
- * THE BAD VENDING MACHINE
- */
- public class Main {
- public static void main(String[] args)
- {
- int LION = 55;
- int COCA = 65;
- int NOCCIOLINE = 50;
- int PATATINE = 45;
- int amount=0,credit=0;
- int choice = 0;
- int coin = 0;
- Scanner scan=new Scanner(System.in);
- while (true) {
- credit=0;
- System.out.println("**********************************");
- System.out.println("* Minibar *");
- System.out.println("* Lion - 55 Premi 1 *");
- System.out.println("* Coca - 65 Premi 2 *");
- System.out.println("* Noccioline - 50 Premi 3 *");
- System.out.println("* Patatine - 45 Premi 4 *");
- System.out.println("**********************************");
- System.out.println("Inserisci la tua scelta.");
- choice = scan.nextInt();
- switch(choice)
- {
- case 1:
- System.out.println("Hai scelto: Lion (0.55€)");
- amount=LION;
- while (credit<LION) {
- System.out.println("Inserisci il valore della moneta, in centesimi");
- coin = scan.nextInt();
- credit+=coin;
- }
- break;
- case 2:
- System.out.println("Hai scelto: Coca (0.65€)");
- amount=COCA;
- while (credit<COCA) {
- System.out.println("Inserisci il valore della moneta, in centesimi");
- coin = scan.nextInt();
- credit+=coin;
- }
- break;
- case 3:
- System.out.println("Hai scelto: Noccioline (0.50€)");
- amount=COCA;
- while (credit<NOCCIOLINE) {
- System.out.println("Inserisci il valore della moneta, in centesimi");
- coin = scan.nextInt();
- credit+=coin;
- }
- break;
- case 4:
- System.out.println("Hai scelto: Patatine (0.45€)");
- amount=PATATINE;
- while (credit<PATATINE) {
- System.out.println("Inserisci il valore della moneta, in centesimi");
- coin = scan.nextInt();
- credit+=coin;
- }
- break;
- default:
- System.out.println("Devi scegliere un valore tra 1 e 4. Grazie!");
- }
- System.out.print("\007");
- System.out.println("Ecco la bibita");
- System.out.println("Il tuo resto è: "+(credit-amount));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement