Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package vending;
- import java.util.Scanner;
- public class Vending {
- Prodotto []p;
- int amount,credit;
- int choice ;
- int coin ;
- public Vending() {
- amount=0;credit=0;
- choice = 0;
- coin = 0;
- p=new Prodotto[4];
- p[0]=new Prodotto(55,"LION",1);
- p[1]=new Prodotto(65,"COCA",2);
- p[2]=new Prodotto(50,"NOCCIOLINE",3);
- p[3]=new Prodotto(45,"PATATINE",4);
- }
- public void setCredit(int credit) {
- this.credit = credit;
- }
- public void stampaMenu() {
- System.out.println("**********************************");
- System.out.println("* Minibar *");
- for(int i=0;i<4;i++)
- System.out.println(p[i]);
- System.out.println("**********************************");
- }
- public void scelta() {
- Coin coin;
- Scanner scan=new Scanner(System.in);
- System.out.println("Inserisci la tua scelta.");
- choice = scan.nextInt();
- switch(choice)
- {
- case 1:
- case 2:
- case 3:
- case 4:
- System.out.println("Hai scelto:"+p[choice-1]);
- amount=p[choice-1].getPrezzo();
- while (credit<amount) {
- System.out.println("Inserisci il valore della moneta, in centesimi");
- coin = new Coin (scan.nextInt());
- if (!coin.isValid()) coin=new Coin(0);
- credit+=coin.getValue();
- }
- break;
- default:
- System.out.println("Devi scegliere un valore tra 1 e 4. Grazie!");
- }
- }
- public void eroga() {
- System.out.print("\007");
- System.out.println("Ecco la bibita");
- System.out.println("Il tuo resto è: "+(credit-amount));
- }
- public static void main(String[] args)
- {
- Vending v = new Vending();
- while (true) {
- v.setCredit(0);
- v.stampaMenu();
- v.scelta();
- v.eroga();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement