Beispiel #1
0
 /**
  * eat food decrease hunger meter and increase in satiability
  *
  * @param food
  */
 public void eat(Food food) {
   // eat Meal or Snack; modifies happinessMeter and hungerMeter
   this.happinessMeter += food.getTastiness();
   this.hungerMeter -= food.getSatiability();
   this.size += food.getFat();
   if (this.hungerMeter <= 0) {
     this.hungerMeter = 0;
   }
 }
Beispiel #2
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;
 }
 public ContentValues putFoodToContentValues(Food food) {
   ContentValues values = new ContentValues();
   values.put(COL_FOOD_NAME, food.getFood_name());
   values.put(COL_PROTEIN, food.getProtein());
   values.put(COL_CARBO, food.getCarbo_hydr());
   values.put(COL_FAT, food.getFat());
   values.put(COL_KCAL, food.getKcal());
   values.put(COL_TYPE_1, food.getType(0).getIndex());
   values.put(COL_TYPE_2, food.getType(1).getIndex());
   values.put(COL_TYPE_3, food.getType(2).getIndex());
   values.put(COL_CATEGORY, food.getCategory().getIndex());
   values.put(COL_FREQUENCY, food.getFrequency());
   if (food.getStrLastTransaction() == "") {
     values.putNull(COL_LAST_TRANSACTION);
   } else {
     values.put(COL_LAST_TRANSACTION, food.getStrLastTransaction());
   }
   return values;
 }