Advertisement
piffy

The Java Vending Machine: ORIGINAL

Nov 25th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.02 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created with IntelliJ IDEA.
  5.  * User: Marcello Missiroli prof.missiroli@gmail.com
  6.  * Date: 24/11/13
  7.  * Time: 14.35
  8.  * THE BAD VENDING MACHINE
  9.  */
  10. public class Main {
  11.  
  12.     public static void main(String[] args)
  13.     {
  14.         int LION = 55;
  15.         int COCA = 65;
  16.         int NOCCIOLINE = 50;
  17.         int PATATINE = 45;
  18.         int amount=0,credit=0;
  19.         int choice = 0;
  20.         int coin = 0;
  21.         Scanner scan=new Scanner(System.in);
  22.         while (true) {
  23.             credit=0;
  24.             System.out.println("**********************************");
  25.             System.out.println("* Minibar *");
  26.             System.out.println("* Lion - 55 Premi 1 *");
  27.             System.out.println("* Coca - 65 Premi 2 *");
  28.             System.out.println("* Noccioline - 50 Premi 3 *");
  29.             System.out.println("* Patatine - 45 Premi 4 *");
  30.             System.out.println("**********************************");
  31.  
  32.             System.out.println("Inserisci la tua scelta.");
  33.             choice = scan.nextInt();
  34.             switch(choice)
  35.  
  36.             {
  37.                 case 1:
  38.                     System.out.println("Hai scelto: Lion (0.55€)");
  39.                     amount=LION;
  40.                     while (credit<LION)  {
  41.                         System.out.println("Inserisci il valore della moneta, in centesimi");
  42.                         coin = scan.nextInt();
  43.                         credit+=coin;
  44.                     }
  45.                     break;
  46.                 case 2:
  47.                     System.out.println("Hai scelto: Coca (0.65€)");
  48.                     amount=COCA;
  49.                     while (credit<COCA)  {
  50.                         System.out.println("Inserisci il valore della moneta, in centesimi");
  51.                         coin = scan.nextInt();
  52.                         credit+=coin;
  53.                     }
  54.                     break;
  55.                 case 3:
  56.                     System.out.println("Hai scelto: Noccioline (0.50€)");
  57.                     amount=COCA;
  58.                     while (credit<NOCCIOLINE)  {
  59.                         System.out.println("Inserisci il valore della moneta, in centesimi");
  60.                         coin = scan.nextInt();
  61.                         credit+=coin;
  62.                     }
  63.                     break;
  64.                 case 4:
  65.                     System.out.println("Hai scelto: Patatine (0.45€)");
  66.                     amount=PATATINE;
  67.                     while (credit<PATATINE)  {
  68.                         System.out.println("Inserisci il valore della moneta, in centesimi");
  69.                         coin = scan.nextInt();
  70.                         credit+=coin;
  71.                     }
  72.                     break;
  73.                 default:
  74.                     System.out.println("Devi scegliere un valore tra 1 e 4. Grazie!");
  75.             }
  76.  
  77.  
  78.             System.out.print("\007");
  79.             System.out.println("Ecco la bibita");
  80.             System.out.println("Il tuo resto è: "+(credit-amount));
  81.  
  82.         }
  83.  
  84.     }
  85.  
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement