Пример #1
0
 public int purchase(int itemchoice, int total, boolean reciept) {
   Food f = foods.get(itemchoice);
   String d = "" + total / 100;
   String c = "" + total % 100;
   if (c.length() < 2) {
     c = "0" + c;
   }
   if (debug) {
     print("Customer is attempting to purchase " + f.getName());
     print("Money entered: $" + d + "." + c + ".");
     d = "" + f.getPrice() / 100;
     c = "" + f.getPrice() % 100;
     if (c.length() < 2) {
       c = "0" + c;
     }
     print("Money required: $" + d + "." + c + ".");
     print("Quantity on hand: " + foodEnd.get(itemchoice));
   }
   if (total > f.getPrice() && foodEnd.get(itemchoice) > 0) {
     foodEnd.set(itemchoice, foodEnd.get(itemchoice) - 1);
     purchased += f.getPrice();
     if (debug) {
       if (reciept) {
         print("    Purchased: " + f.getName());
         print("    Price:     " + f.getPrice());
         print("    Change:    " + (total -= f.getPrice()));
         print("    Calories:  " + f.getCalories());
         print("    Fat:       " + f.getFat());
         print("    Carbs:     " + f.getCarbohydrates());
         print("    Protein:   " + f.getProtein());
       }
       d = "" + total / 100;
       c = "" + total % 100;
       if (c.length() < 2) {
         c = "0" + c;
       }
       print("Customer now has $" + d + "." + c + ".");
     }
   } else {
     if (debug) {
       if (total < f.getPrice()) {
         print("NO PURCHASE, INSUFFICIENT FUNDS.");
       } else // implied quantity is <1
       {
         print("NO PURCHASE, INSUFFICIENT QUANTITY.");
       }
     }
   }
   return total;
 }