repl.it
@imigames/

vending test123

Java

No description

fork
loading
Files
  • Main.java
  • FoodItem.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import java.util.Scanner;


class Main {
   
    //Vending relating variableds
    static double totalIncome = 0;
  
   
  static FoodItem marsObject= new FoodItem("Mars Bar", 0.75, 10);
  static FoodItem colaObject = new FoodItem("Coca Cola", 1, 10);
  static FoodItem eugeniaObject = new FoodItem("Eugenia", 0.85, 10);
  static FoodItem waterObject = new FoodItem("Water", 0.75, 10);
  static FoodItem crispsObject = new FoodItem("Crisps", 0.75, 10);    
    static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args) 
    {     





        double amount = 0;

        while (true)
        {
          while(true){
            if(true){
            System.out.println("Insert amount: ");
             amount =amount + keyboard.nextDouble();
             keyboard.nextLine();}
             else{}
            



           if (amount != 0.05 && amount != 0.10 && amount !=0.20 && amount != 0.50 && amount != 1)
         {System.out.println("Incorect Coin, please insert £0.05 , £0.10 , £0.20 , £0.50 , £1");}
            else{break;}
          }
          
           System.out.println("Hi! Which item do you like to buy?");
           String itemName = keyboard.nextLine();
           
           
           if (itemName.equalsIgnoreCase("exit"))
                   {
                       break;
                   }

         //  System.out.println("Insert amount: ");
         //   double amount = keyboard.nextDouble();keyboard.nextLine();
            



     //      if (amount != 0.05 && amount != 0.10 && amount !=0.20 && amount != 0.50 && amount != 1)
     //     {System.out.println("Incorect Coin, please insert £0.05 , £0.10 , £0.20 , £0.50 , £1");}


           
                        

           if (itemName.equalsIgnoreCase("Water")){
           buyItem(waterObject, amount);
        
        }
          else
              if (itemName.equalsIgnoreCase("Mars Bar")){
           buyItem(marsObject, amount);
        
        }
              
              else if(itemName.equalsIgnoreCase("Crisps")  ){
           buyItem(crispsObject, amount);
              }
              else if(itemName.equalsIgnoreCase("Eugenia")  ){
           buyItem(eugeniaObject, amount);
              }
              else if(itemName.equalsIgnoreCase("Coca Cola")  ){
           buyItem(colaObject, amount);
              }
              else {
                  System.out.println("Wrong selection!!!");
              }
        System.out.println();
        }
           
        
        reporting();
        
    }
    
    
    
    public static double buyItem(FoodItem item, double amount)
    {
      
        double change = 0;
        String name = item.getName();
         if(amount >= item.getPrice())
          {
              item.decreaseQuantity();
              change = amount - item.getPrice();
              totalIncome += item.getPrice();
          System.out.println("Enjoy your: " + item.getName() );
          }
             else 
                {
                 System.out.println("Sorry. Not enough money!!!! The price for  "  + item.getName() + " is " + item.getPrice());
                 change=amount;
                }
        System.out.println("Please take your change" + change);
        return change;
          
          }
   public static void reporting()
   {
       System.out.println("******************");
       System.out.println("******Report******");
       System.out.println("Total collected money:" + totalIncome);
       System.out.println("Remaining Water: " + waterObject.getQuantity() );
       System.out.println("Remaining Coca Cola: " + colaObject.getQuantity() );
       System.out.println("Remaining Eugenia: " + eugeniaObject.getQuantity() );
       System.out.println("Remaining Crisps: " + crispsObject.getQuantity() );
       System.out.println("Remaining Mars Bar: " + marsObject.getQuantity() );
       System.out.println("******************");
       
       
       
       
   }        
}