@Override
  public void onHandEvent(HandEvent handEvent) {
    Log.i(TAG, "Ari " + handEvent.type);
    String eventType = handEvent.type.toString();

    if (eventType.equals("OPEN_HAND")) {
      playSuccessSound();
      if (foodItem.isLastStep()) {
        resetTraining();
      } else {
        mAri.stop();
        finish();
      }

    } else if (eventType.equals("CLOSED_HAND")) {
      playSuccessSound();
      if (foodItem.isLastStep()) {
        starGetIdActivity();
      } else {
        if (play) pauseTraining();
      }

    } else if (eventType.equals("V_SIGN")) {
      playSuccessSound();
      if (!play) startTraining();
    } else if (eventType.equals("LEFT_SWIPE")) {
      playSuccessSound();
      manualNextStep();

    } else if (eventType.equals("RIGHT_SWIPE")) {
      playSuccessSound();
      previousStep();
    }
  }
 private void nextStep() {
   playNavigationSound();
   foodItem.nextStep();
   displayStepImage();
   if (!foodItem.isFinishTraining()) {
     mHandler.postDelayed(stepDelayRunnable, STEP_DISPLAY_TIME);
     countDownTimer.start();
   }
 }
 private void resetTraining() {
   if (foodItem.isFinishTraining()) {
     foodItem.setFinishTraining(false);
     playPauseImageView.setVisibility(View.VISIBLE);
   }
   play = true;
   foodItem.setCurrentStep(1);
   displayStepImage();
   startTraining();
 }
  public final void testSetQuantity() {
    // Test normal
    final FoodItem item = new FoodItem();
    final String quantity = "quant";
    item.setQuantity(quantity);
    assertEquals(quantity, item.getQuantity());

    // Test null
    item.setQuantity(null);
    assertEquals("", item.getQuantity());
  }
 private void previousStep() {
   if (!foodItem.previousStep()) {
     if (foodItem.isFinishTraining()) {
       foodItem.setFinishTraining(false);
       playPauseImageView.setVisibility(View.VISIBLE);
     }
     displayStepImage();
   } else {
     finish();
   }
 }
Example #6
0
 public void testsetItemDescription() {
   byte[] sourceline1 =
       "This is a test,grams,100,49.00,0.30,10.60,0.2,piece,1,96,0.7,23.2,0,,,,,,".getBytes();
   FoodItem result1 = null;
   try {
     result1 = new FoodItem(sourceline1);
   } catch (InvalidSourceLineException e) {
     e.printStackTrace();
   }
   result1.setItemDescription("new text");
   Assert.assertEquals("testsetItemDescription failed", "new text", result1.getItemDescription());
 }
 private void manualNextStep() {
   if (!foodItem.isFinishTraining()) {
     if (foodItem.isLastStep()) {
       playPauseImageView.setVisibility(View.INVISIBLE);
       timerTextView.setText("");
     } else {
       playPauseImageView.setVisibility(View.VISIBLE);
       pauseTraining();
     }
     foodItem.nextStep();
     displayStepImage();
   } else {
     starGetIdActivity();
   }
 }
Example #8
0
File: Player.java Project: pbos/kth
  /**
   * Eats an item.
   *
   * @param item The item to eat.
   * @return The item if it was edible, or null if it didn't exist or was unedible.
   */
  public Item eat(String itemName) {
    Item item = getItem(itemName);

    if (item == null) {
      return null;
    }

    // Controls if the item is food.
    if (item instanceof FoodItem) {
      FoodItem food = (FoodItem) item;
      movesLeft += food.getEnergy();
      return removeItem(itemName);
    }

    return null;
  }
 private void startTraining() {
   if (!foodItem.isFinishTraining()) {
     play = true;
     setPlayPauseIcon(true);
     mHandler.postDelayed(stepDelayRunnable, STEP_DISPLAY_TIME);
     countDownTimer.start();
   }
 }
Example #10
0
 public boolean isInShoppingList(FoodItem food) {
   for (int i = 0; i < foodItems.size(); i++) {
     if (foodItems.get(i).getName().equals(food.getName())) {
       return true;
     }
   }
   return false;
 }
  public final void testSetName() {
    // Test normal
    final FoodItem item = new FoodItem();
    final String name = "aname";
    item.setName(name);
    assertEquals(name, item.getName());

    // Test null
    //        try
    //        {
    //            item.setName(null);
    //            fail("Item.setName(String) must not allow null as parameter");
    //        } catch (AssertionError e)
    //        {
    //            //No code as the exception SHOULD be thrown.
    //        }
  }
  public final void testSetExpiry() {
    // Test normal operation
    final FoodItem item = new FoodItem();
    final Calendar nowCal = Calendar.getInstance();

    item.setExpiry(nowCal.getTime());

    final Calendar itemCal = Calendar.getInstance();
    itemCal.setTime(item.getExpiry());

    assertEquals(nowCal.get(Calendar.DAY_OF_MONTH), itemCal.get(Calendar.DAY_OF_MONTH));
    assertEquals(nowCal.get(Calendar.MONTH), itemCal.get(Calendar.MONTH));
    assertEquals(nowCal.get(Calendar.YEAR), itemCal.get(Calendar.YEAR));

    // Test null
    item.setExpiry(null);
    assertNull(item.getExpiry());
  }
 public void run() {
   if (play && currentTime <= 1) {
     if (!foodItem.isLastStep()) {
       nextStep();
     } else {
       nextStep();
       timerTextView.setText("");
       playPauseImageView.setVisibility(View.INVISIBLE);
     }
   }
 }
Example #14
0
 public boolean removeItem(FoodItem itemToRemove) {
   // return true if removal is successful
   // return false if no item is removed
   for (int i = 0; i < foodItems.size(); i++) {
     if (foodItems.get(i).getName().equals(itemToRemove.getName())) {
       foodItems.remove(i);
       return true;
     }
   }
   return false;
 }
  /*
   * Class under test for void FoodItem(String, String, Date)
   */
  public final void testFoodItemStringStringDate() {
    final String itemName = "aName";
    final String itemQuantity = "aQuantity";

    final Calendar itemDate = Calendar.getInstance();
    final int day = 23;
    final int month = 5;
    final int year = 2004;
    itemDate.set(year, month, day, 15, 22);

    final FoodItem item = new FoodItem(itemName, itemQuantity, itemDate.getTime());

    final Calendar returnedItemDate = Calendar.getInstance();
    returnedItemDate.setTime(item.getExpiry());
    final int returnedDay = returnedItemDate.get(Calendar.DAY_OF_MONTH);
    final int returnedMonth = returnedItemDate.get(Calendar.MONTH);
    final int returnedYear = returnedItemDate.get(Calendar.YEAR);

    assertEquals(itemName, item.getName());
    assertEquals(itemQuantity, item.getQuantity());
    assertEquals(day, returnedDay);
    assertEquals(month, returnedMonth);
    assertEquals(year, returnedYear);
  }
Example #16
0
  /**
   * This method contains the definition for the 'update' method of the observer interface. This
   * method updates the Food Stock panel in the user interface window.
   */
  public void update(Observable observable, Object obj) {
    VendingMachine machine = (VendingMachine) observable;
    itemList = (Hashtable) obj;
    Enumeration e = itemList.elements();

    for (int i = 0; e.hasMoreElements(); i++) { // Display the updates in the available Food Stocks
      VendingMachine.FoodStock stock = (VendingMachine.FoodStock) e.nextElement();
      FoodItem item = stock.item;

      itemLabelArray[i].setText(item.getDescription());

      Integer code = item.getItemCode();
      String str = code.toString();
      codeLabelArray[i].setText("Item Code: " + str);

      Double price = item.getPrice();
      String str1 = price.toString();
      priceLabelArray[i].setText("Price: " + str1);

      Integer quant = machine.GetQuantity(code);
      String str2 = quant.toString();
      quantityLabelArray[i].setText("Quantity: " + str2);
    }
  }
Example #17
0
 public void alphabeticalSort() {
   Collections.sort(foodItems, FoodItem.getAlphabeticalComparator());
   howSorted = 1;
 }
Example #18
0
  /**
   * main goal is to test the constructor, but implicitly all other methods are also tested, except
   * compareTo, which is tested separately
   */
  public void testFoodItemTest() {
    byte[] sourceline1 =
        "Apple| imported| raw,grams,100,49.00,0.30,10.60,0.2,piece,1,96,0.7,23.2,0,,,,,,"
            .getBytes();
    byte[] sourceline2 =
        "Bread| white| bake-off| ready to eat,grams,100,259.00,9.10,50.20,1.6,slice=50,1,130,4.55,25.1,0.8,,,,,,"
            .getBytes();
    byte[] sourceline3 =
        "Bread| white| industry made,grams,100,258.00,9.40,46.90,2.9,slice (25 grams)=25,1,65,2.35,11.725,0.725,slice (50 grams)=50,1,129,4.7,23,1.45"
            .getBytes();
    byte[] sourceline4 = "test without unit description,,100,258.00,9.40,46.90,2.9".getBytes();
    byte[] sourceline5 = "test without standard amount,piece,,258.00,9.40,46.90,2.9".getBytes();
    byte[] sourceline6 = "test without kcals proteins and fats,piece,1,,,46.90,".getBytes();
    byte[] sourceline7 = "first unit has invalid carb value,piece,1,,,,,,,blabla".getBytes();
    byte[] sourceline8 = "first unit has invalid carb value,piece,1,,,,,,,".getBytes();
    byte[] sourceline9 =
        "Bread| white| bake-off| ready to eat,grams=100.1,100,259.00,9.10,50.20,1.6,slice=50,1,130,4.55,25.1,0.8,,,,,,"
            .getBytes();
    byte[] sourceline10 =
        "Bread| white| bake-off| ready to eat,grams=100,100,259.00,9.10,50.20,1.6,slice=hello,1,130,4.55,25.1,0.8,,,,,,"
            .getBytes();
    byte[] sourceline11 = "invalid kcal value,piece,1,blabla,,10,,,,".getBytes();
    byte[] sourceline12 = "invalid protein value,piece,1,,blabla,10,,,,".getBytes();
    byte[] sourceline13 = "invalid fat value,piece,1,,,10,blabla,,,".getBytes();
    FoodItem result1 = null;
    FoodItem result2 = null;
    FoodItem result3 = null;
    FoodItem result4 = null;
    FoodItem result5 = null;
    FoodItem result6 = null;
    try {
      result1 = new FoodItem(sourceline1);

    } catch (InvalidSourceLineException e) {
      e.printStackTrace();
    }
    try {
      result2 = new FoodItem(sourceline2);

    } catch (InvalidSourceLineException e) {
      e.printStackTrace();
    }
    try {
      result3 = new FoodItem(sourceline3);

    } catch (InvalidSourceLineException e) {
      e.printStackTrace();
    }
    try {
      result4 = new FoodItem(sourceline4);

    } catch (InvalidSourceLineException e) {
      e.printStackTrace();
    }
    try {
      result5 = new FoodItem(sourceline5);

    } catch (InvalidSourceLineException e) {
      e.printStackTrace();
    }
    try {
      result6 = new FoodItem(sourceline6);

    } catch (InvalidSourceLineException e) {
      e.printStackTrace();
    }

    // assert result 1
    Assert.assertEquals(
        "ItemDescription of sourceline1 not correctly read",
        "Apple, imported, raw",
        result1.getItemDescription());
    Assert.assertEquals(
        "UnitDescription 1 in sourceLine1 not correctly read",
        "grams",
        result1.getUnit(0).getDescription());
    Assert.assertEquals(
        "standardamount 1 value of sourceline1 not correctly read",
        100.00,
        result1.getUnit(0).getStandardAmount(),
        0.0001);
    Assert.assertEquals(
        "kcal value 1 of sourceline1 not correctly read", 49, result1.getUnit(0).getKcal());
    Assert.assertEquals(
        "protein value 1 of sourceline1 not correctly read",
        0.3,
        result1.getUnit(0).getProtein(),
        0.0001);
    Assert.assertEquals(
        "fat value of 1 sourceline1 not correctly read", 0.2, result1.getUnit(0).getFat(), 0.0001);
    Assert.assertEquals(
        "carb value of 1 sourceline1 not correctly read",
        10.6,
        result1.getUnit(0).getCarbs(),
        0.0001);
    Assert.assertEquals(
        "UnitWeight value 1 of sourceline1 not correctly read", -1, result1.getUnit(0).getWeight());
    Assert.assertEquals(
        "number of units of sourceline1 not correctly read", 2, result1.getNumberOfUnits());
    Assert.assertEquals(
        "UnitDescription 2 in sourceline1 not correctly read",
        "piece",
        result1.getUnit(1).getDescription());
    Assert.assertEquals(
        "standardamount value 2 of sourceline1 not correctly read",
        1,
        result1.getUnit(1).getStandardAmount(),
        0.0001);
    Assert.assertEquals(
        "kcal value 2 of sourceline1 not correctly read", 96, result1.getUnit(1).getKcal());
    Assert.assertEquals(
        "protein value 2 of sourceline1 not correctly read",
        0.7,
        result1.getUnit(1).getProtein(),
        0.0001);
    Assert.assertEquals(
        "fat value 2 of sourceline1 not correctly read", 0, result1.getUnit(1).getFat(), 0.0001);
    Assert.assertEquals(
        "carb value 2 of sourceline1 not correctly read",
        23.2,
        result1.getUnit(1).getCarbs(),
        0.0001);
    Assert.assertEquals(
        "UnitWeight value 2 of sourceline1 not correctly read", -1, result1.getUnit(1).getWeight());

    // assert result 3
    Assert.assertEquals(
        "ItemDescription of sourceline3 not correctly read",
        "Bread, white, industry made",
        result3.getItemDescription());
    Assert.assertEquals(
        "UnitDescription 1 in sourceline3 not correctly read",
        "grams",
        result3.getUnit(0).getDescription());
    Assert.assertEquals(
        "standardamount value 1 of sourceline3 not correctly read",
        100.00,
        result3.getUnit(0).getStandardAmount(),
        0.0001);
    Assert.assertEquals(
        "kcal value 1 of sourceline3 not correctly read", 258, result3.getUnit(0).getKcal());
    Assert.assertEquals(
        "protein value 1  of sourceline3 not correctly read",
        9.40,
        result3.getUnit(0).getProtein(),
        0.0001);
    Assert.assertEquals(
        "fat value 1 of sourceline3 not correctly read", 2.9, result3.getUnit(0).getFat(), 0.0001);
    Assert.assertEquals(
        "carb value 1 of sourceline3 not correctly read",
        46.90,
        result3.getUnit(0).getCarbs(),
        0.0001);
    Assert.assertEquals(
        "UnitWeight value 1 of sourceline3 not correctly read", -1, result3.getUnit(0).getWeight());
    Assert.assertEquals(
        "number of units  of sourceline3 not correctly read", 3, result3.getNumberOfUnits());
    Assert.assertEquals(
        "UnitDescription 2 in sourceLine3 not correctly read",
        "slice (25 grams)",
        result3.getUnit(1).getDescription());
    Assert.assertEquals(
        "standardamount value 2 of sourceline3 not correctly read",
        1,
        result3.getUnit(1).getStandardAmount(),
        0.0001);
    Assert.assertEquals(
        "kcal value 2 of sourceline3 not correctly read", 65, result3.getUnit(1).getKcal());
    Assert.assertEquals(
        "protein value 2 of sourceline3 not correctly read",
        2.35,
        result3.getUnit(1).getProtein(),
        0.0001);
    Assert.assertEquals(
        "fat value 2 of sourceline3 not correctly read",
        0.725,
        result3.getUnit(1).getFat(),
        0.0001);
    Assert.assertEquals(
        "carb value 2 of sourceline3 not correctly read",
        11.725,
        result3.getUnit(1).getCarbs(),
        0.0001);
    Assert.assertEquals(
        "UnitWeight value 2  of sourceline3 not correctly read",
        25,
        result3.getUnit(1).getWeight());
    // slice (50 grams)=50,1,129,4.7,23,1.45
    Assert.assertEquals(
        "UnitDescription 3 in sourceLine3 not correctly read",
        "slice (50 grams)",
        result3.getUnit(2).getDescription());
    Assert.assertEquals(
        "standardamount value 3 of sourceline3 not correctly read",
        1,
        result3.getUnit(2).getStandardAmount(),
        0.0001);
    Assert.assertEquals(
        "kcal value 3 of sourceline3 not correctly read", 129, result3.getUnit(2).getKcal());
    Assert.assertEquals(
        "protein value 3 of sourceline3 not correctly read",
        4.7,
        result3.getUnit(2).getProtein(),
        0.0001);
    Assert.assertEquals(
        "fat value 3 of sourceline3 not correctly read", 1.45, result3.getUnit(2).getFat(), 0.0001);
    Assert.assertEquals(
        "carb value 3 of sourceline3 not correctly read",
        23,
        result3.getUnit(2).getCarbs(),
        0.0001);
    Assert.assertEquals(
        "UnitWeight value 3  of sourceline3 not correctly read",
        50,
        result3.getUnit(2).getWeight());

    // assert result 2 slice=50,1,130,4.55,25.1,0.8,,,,,,
    Assert.assertEquals(
        "UnitDescription 3 in sourceLine2 not correctly read",
        "slice",
        result2.getUnit(1).getDescription());
    Assert.assertEquals(
        "standardamount value 3 of sourceline2 not correctly read",
        1,
        result2.getUnit(1).getStandardAmount(),
        0.0001);
    Assert.assertEquals(
        "kcal value 3 of sourceline2 not correctly read", 130, result2.getUnit(1).getKcal());
    Assert.assertEquals(
        "protein value 3 of sourceline2 not correctly read",
        4.55,
        result2.getUnit(1).getProtein(),
        0.0001);
    Assert.assertEquals(
        "fat value 3 of sourceline2 not correctly read", 0.8, result2.getUnit(1).getFat(), 0.0001);
    Assert.assertEquals(
        "carb value 3 of sourceline2 not correctly read",
        25.1,
        result2.getUnit(1).getCarbs(),
        0.0001);
    Assert.assertEquals(
        "UnitWeight value 3  of sourceline2 not correctly read",
        50,
        result2.getUnit(1).getWeight());

    // result 4
    Assert.assertEquals(
        "UnitDescription 4 in sourceLine4 not correctly read",
        "",
        result4.getUnit(0).getDescription());
    // result 5
    Assert.assertEquals(
        "Standardamount value 5 in sourceLine5 not correctly read",
        1,
        result5.getUnit(0).getStandardAmount());
    // result 6
    Assert.assertEquals(
        "kcal value 6 in sourceline6 not correctly read", -1, result6.getUnit(0).getKcal());
    Assert.assertEquals(
        "protein value 6 in sourceline6 not correctly read",
        -1.0,
        result6.getUnit(0).getProtein(),
        0.0001);
    Assert.assertEquals(
        "fat value 6 in sourceline6 not correctly read", -1.0, result6.getUnit(0).getFat(), 0.0001);
    // result 7
    int position = 0;
    String text = null;
    FoodItem result7;
    try {
      result7 = new FoodItem(sourceline7);
    } catch (InvalidSourceLineException e) {
      position = e.getPosition();
      text = e.getMessage();
    }
    Assert.assertEquals("result7 generates exception with wrong position value", 45, position);
    Assert.assertEquals(
        "result7 generates exception with wrong message text",
        "First Unit does not contain a parsable Carb value",
        text);
    // result 8
    position = 0;
    text = null;
    FoodItem result8;
    try {
      result8 = new FoodItem(sourceline8);
    } catch (InvalidSourceLineException e) {
      position = e.getPosition();
      text = e.getMessage();
    }
    Assert.assertEquals("result8 generates exception with wrong position value", 43, position);
    Assert.assertEquals(
        "result8 generates exception with wrong message text",
        "First Unit does not contain a parsable Carb value",
        text);
    // result 9
    position = 0;
    text = null;
    FoodItem result9;
    try {
      result9 = new FoodItem(sourceline9);
    } catch (InvalidSourceLineException e) {
      position = e.getPosition();
      text = e.getMessage();
    }
    Assert.assertEquals("result9 generates exception with wrong position value", 43, position);
    Assert.assertEquals(
        "result9 generates exception with wrong message text",
        "Invalid value for unit weight, must be Integer value",
        text);
    // result 10
    position = 0;
    text = null;
    FoodItem result10;
    try {
      result10 = new FoodItem(sourceline10);
    } catch (InvalidSourceLineException e) {
      position = e.getPosition();
      text = e.getMessage();
    }
    Assert.assertEquals("result10 generates exception with wrong position value", 79, position);
    Assert.assertEquals(
        "result10 generates exception with wrong message text",
        "Invalid value for unit weight, must be Integer value",
        text);
    // result 11
    position = 0;
    text = null;
    FoodItem result11;
    try {
      result11 = new FoodItem(sourceline11);
    } catch (InvalidSourceLineException e) {
      position = e.getPosition();
      text = e.getMessage();
    }
    Assert.assertEquals("result11 generates exception with wrong position value", 28, position);
    Assert.assertEquals(
        "result11 generates exception with wrong message text",
        "Invalid value for kcal, must be decimal value",
        text);
    // result 12
    position = 0;
    text = null;
    FoodItem result12;
    try {
      result12 = new FoodItem(sourceline12);
    } catch (InvalidSourceLineException e) {
      position = e.getPosition();
      text = e.getMessage();
    }
    Assert.assertEquals("result12 generates exception with wrong position value", 32, position);
    Assert.assertEquals(
        "result12 generates exception with wrong message text",
        "Invalid value for protein, must be decimal value",
        text);
    // result 13
    position = 0;
    text = null;
    FoodItem result13;
    try {
      result13 = new FoodItem(sourceline13);
    } catch (InvalidSourceLineException e) {
      position = e.getPosition();
      text = e.getMessage();
    }
    Assert.assertEquals("result13 generates exception with wrong position value", 32, position);
    Assert.assertEquals(
        "result13 generates exception with wrong message text",
        "Invalid value for fat, must be decimal value",
        text);
  }
    @Override
    public void run() {
      // TODO Auto-generated method stub

      if (choice == 0) {

        String selection = DBHelperRestaurent.Name + " LIKE '%" + searchName + "%'";
        MainActivity.databaseAdapter.open();
        cursor =
            MainActivity.databaseAdapter.database.query(
                DBHelperRestaurent.TableName, columnsRestaurent, selection, null, null, null, null);
        Log.d("cursor made", "done");
        RestaurentInfo restInfo;
        searchRestResult.clear();
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
          restInfo = new RestaurentInfo();
          restInfo.setId(cursor.getLong(0));
          restInfo.setName(cursor.getString(1));
          restInfo.setAddress(cursor.getString(2));
          restInfo.setLatitude(cursor.getFloat(3));
          restInfo.setLongitude(cursor.getFloat(4));
          restInfo.setRank(cursor.getFloat(5));

          Log.d("searching", restInfo.toString());

          searchRestResult.add(restInfo);
          handler.sendEmptyMessage(1);

          cursor.moveToNext();
          MainActivity.databaseAdapter.close();
        }

      } else if (choice == 1) {
        String selection = DBHelperMenu.MenuName + " LIKE '%" + searchName + "%'";
        DataBaseAdapterMenu menudbAdapter =
            new DataBaseAdapterMenu(getActivity().getApplicationContext());
        menudbAdapter.open();
        SQLiteDatabase database = menudbAdapter.getDatabase();
        cursor =
            database.query(
                DBHelperMenu.TableNameMenu, columnsFood, selection, null, null, null, null);

        Log.d("cursor is null", (cursor == null) + "");

        FoodItem foodItem;
        searchFoodResult.clear();

        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
          foodItem = new FoodItem();
          foodItem.setRest_Id(cursor.getLong(0));
          foodItem.setName(cursor.getString(1));
          foodItem.setPrice(cursor.getInt(2));

          Log.d("New favourite", foodItem.toString());

          searchFoodResult.add(foodItem);
          handler.sendEmptyMessage(1);

          cursor.moveToNext();

          menudbAdapter.close();
        }
      }
    }
Example #20
0
    public void actionPerformed(ActionEvent event) {
      if (displayNutri.isSelected()
          && codeText.getText() != null) { // for Display Nutritional Info Button
        try {
          intValue2 = Integer.valueOf(codeText1.getText()); // Get the text value of Item Code
        } catch (NumberFormatException e) {
          display = "Enter Correct Item Code"; // Display Error Message for Wrong Input
          displayLabel.setForeground(Color.magenta);
          displayLabel.setText(display);
          codeText1.setText(null);
          return;
        }
        FoodItem item =
            DisplayNutritionalInfo(intValue2); // Call to the Method to Display Nutritional Info

        if (item != null) {
          calories =
              item.GetCalories(); // Get the nutrional Info of the Item Code from the FoodItem
          sugar = item.GetSugarContents();
          fats = item.GetFatContents();

          display =
              "Calorific Value = "
                  + calories
                  + "   Sugar Contents = "
                  + sugar
                  + "gms"
                  + "   Fat Contents = "
                  + fats
                  + "gms";
          displayLabel.setForeground(Color.magenta);
          displayLabel.setText(display);
        } else {
          display = "Enter Correct item Code"; // Display Error Message for Wrong Input
          displayLabel.setForeground(Color.magenta);
          displayLabel.setText(display);
          codeText.setText(null);
        }
      }

      if (querySuggest.isSelected()
          && calorieText.getText() != null) { // for Display Query Suggestion Button
        try {
          intValue2 =
              Integer.valueOf(calorieText.getText()); // Get the text value of Maximum Calorie Limit
        } catch (NumberFormatException e) {
          display = "Enter Correct Calorie Limit"; // Display Error Message for Wrong Input
          displayLabel.setForeground(Color.magenta);
          displayLabel.setText(display);
          calorieText.setText(null);
          return;
        }

        if (intValue2 < 0) {
          display =
              "Enter Correct Calorie Limit"; // Display Error Message for Wrong (negative) Input
          displayLabel.setForeground(Color.magenta);
          displayLabel.setText(display);
          calorieText.setText(null);
        } else {
          Hashtable itemList = DisplaySuggestion();
          Enumeration e = itemList.elements();

          String finalStr = "";
          for (int i = 0;
              e.hasMoreElements();
              i++) { // Get the list of Food items below the entered Calorie Limit
            VendingMachine.FoodStock stock = (VendingMachine.FoodStock) e.nextElement();
            FoodItem item = stock.item;
            if (item.GetCalories() <= intValue2) {
              flag = 1;
              if (!finalStr.equals("")) {
                finalStr = finalStr + " , " + item.getDescription();
              } else {
                finalStr = item.getDescription();
              }
            }
          }
          if (flag == 1) {
            display = finalStr; // Display the list of Food items below the entered Calorie Limit
            displayLabel.setForeground(Color.magenta);
            displayLabel.setText(display);
            flag = 0;
          } else {
            display =
                "No items in the Machine below Calorie Limit "
                    + intValue2; // No Items below the entered Calorie Limit
            displayLabel.setForeground(Color.magenta);
            displayLabel.setText(display);
          }
        }
      }
    }
Example #21
0
 public void testFoodItem2() {
   byte[] sourceline1 =
       "Apple| imported| raw,grams,100,49.00,0.30,10.60,0.2,piece,1,96,0.7,23.2,0,,,,,,"
           .getBytes();
   FoodItem resultx = null;
   try {
     resultx = new FoodItem(sourceline1);
   } catch (InvalidSourceLineException e) {
     e.printStackTrace();
   }
   FoodItem result1 = new FoodItem(resultx);
   // assert result 1
   Assert.assertEquals(
       "ItemDescription of sourceline1 not correctly read",
       "Apple, imported, raw",
       result1.getItemDescription());
   Assert.assertEquals(
       "UnitDescription 1 in sourceLine1 not correctly read",
       "grams",
       result1.getUnit(0).getDescription());
   Assert.assertEquals(
       "standardamount 1 value of sourceline1 not correctly read",
       100.00,
       result1.getUnit(0).getStandardAmount(),
       0.0001);
   Assert.assertEquals(
       "kcal value 1 of sourceline1 not correctly read", 49, result1.getUnit(0).getKcal());
   Assert.assertEquals(
       "protein value 1 of sourceline1 not correctly read",
       0.3,
       result1.getUnit(0).getProtein(),
       0.0001);
   Assert.assertEquals(
       "fat value of 1 sourceline1 not correctly read", 0.2, result1.getUnit(0).getFat(), 0.0001);
   Assert.assertEquals(
       "carb value of 1 sourceline1 not correctly read",
       10.6,
       result1.getUnit(0).getCarbs(),
       0.0001);
   Assert.assertEquals(
       "UnitWeight value 1 of sourceline1 not correctly read", -1, result1.getUnit(0).getWeight());
   Assert.assertEquals(
       "number of units of sourceline1 not correctly read", 2, result1.getNumberOfUnits());
   Assert.assertEquals(
       "UnitDescription 2 in sourceline1 not correctly read",
       "piece",
       result1.getUnit(1).getDescription());
   Assert.assertEquals(
       "standardamount value 2 of sourceline1 not correctly read",
       1,
       result1.getUnit(1).getStandardAmount(),
       0.0001);
   Assert.assertEquals(
       "kcal value 2 of sourceline1 not correctly read", 96, result1.getUnit(1).getKcal());
   Assert.assertEquals(
       "protein value 2 of sourceline1 not correctly read",
       0.7,
       result1.getUnit(1).getProtein(),
       0.0001);
   Assert.assertEquals(
       "fat value 2 of sourceline1 not correctly read", 0, result1.getUnit(1).getFat(), 0.0001);
   Assert.assertEquals(
       "carb value 2 of sourceline1 not correctly read",
       23.2,
       result1.getUnit(1).getCarbs(),
       0.0001);
   Assert.assertEquals(
       "UnitWeight value 2 of sourceline1 not correctly read", -1, result1.getUnit(1).getWeight());
 }
Example #22
0
  public void testcompareTo() throws InvalidSourceLineException {
    byte[] sourceline1 =
        "This is a test with special characters e e e e e e,grams,100,49.00,0.30,10.60,0.2,piece,1,96,0.7,23.2,0,,,,,,"
            .getBytes();
    byte[] sourceline2 =
        "This is a test with special characters e � � � � E,grams,100,259.00,9.10,50.20,1.6,slice=50,1,130,4.55,25.1,0.8,,,,,,"
            .getBytes();
    byte[] sourceline3 =
        "This is a test with special characters e � � � � a,grams,100,258.00,9.40,46.90,2.9,slice (25 grams)=25,1,65,2.35,11.725,0.725,slice (50 grams)=50,1,129,4.7,23,1.45"
            .getBytes();
    byte[] sourceline4 = "abcdaaa,,100,258.00,9.40,46.90,2.9".getBytes();
    byte[] sourceline5 = "abcd�bb,piece,,258.00,9.40,46.90,2.9".getBytes();
    byte[] sourceline6 = "abcd�bbzz,piece,1,,,46.90,".getBytes();
    byte[] sourceline7 = "first unit has invalid carb value,piece,1,,,,,,,blabla".getBytes();
    byte[] sourceline8 = "first unit has invalid carb value,piece,1,,,,,,,".getBytes();
    byte[] sourceline9 =
        "Bread| white| bake-off| ready to eat,grams=100.1,100,259.00,9.10,50.20,1.6,slice=50,1,130,4.55,25.1,0.8,,,,,,"
            .getBytes();
    byte[] sourceline10 =
        "Bread| white| bake-off| ready to eat,grams=100,100,259.00,9.10,50.20,1.6,slice=hello,1,130,4.55,25.1,0.8,,,,,,"
            .getBytes();
    byte[] sourceline11 = "invalid kcal value,piece,1,blabla,,10,,,,".getBytes();
    byte[] sourceline12 = "invalid protein value,piece,1,,blabla,10,,,,".getBytes();
    byte[] sourceline13 = "invalid fat value,piece,1,,,10,blabla,,,".getBytes();

    FoodItem result1 = new FoodItem(sourceline1);
    FoodItem result2 = new FoodItem(sourceline2);
    FoodItem result3 = new FoodItem(sourceline3);
    FoodItem result4 = new FoodItem(sourceline4);
    FoodItem result5 = new FoodItem(sourceline5);
    FoodItem result6 = new FoodItem(sourceline6);

    Assert.assertEquals("comparison result1 to result2 failed", 0, result1.compareTo(result2));
    Assert.assertEquals("comparison result2 to result3 failed", 1, result2.compareTo(result3));
    Assert.assertEquals("comparison result3 to result2 failed", -1, result3.compareTo(result2));
    Assert.assertEquals("comparison result4 to result5 failed", -1, result4.compareTo(result5));
    Assert.assertEquals("comparison result5 to result4 failed", 1, result5.compareTo(result4));
    Assert.assertEquals("comparison result5 to result6 failed", -1, result5.compareTo(result6));
    Assert.assertEquals("comparison result6 to result5 failed", 1, result6.compareTo(result5));
    Assert.assertEquals("comparison result1 to result4 failed", 1, result1.compareTo(result4));
    Assert.assertEquals("comparison result4 to result1 failed", -1, result4.compareTo(result1));
  }
Example #23
0
 public void expirationSort() {
   Collections.sort(foodItems, FoodItem.getExpirationComparator());
   howSorted = 2;
 }
Example #24
0
  /** @param parentUI an instance of MainUI class */
  public ConsumerUI(MainUI parentUI) {
    super("SmartCal Vending Machine - Consumer Operations");
    super.setLocation(200, 10);
    this.parentUI = parentUI;

    VendingMachine machine = parentUI.getVendingMachine(); // Get an instance of Vending Machine
    machine.addObserver(
        this); // Register ConsumerUI as an observer to receive VendingMachine updates

    Container container1 = getContentPane();
    container1.setLayout(new BoxLayout(container1, BoxLayout.Y_AXIS));

    // itemPanel = Food Stock Panel
    itemPanel = new JPanel(new GridLayout(0, 4));
    itemPanel.setBorder(BorderFactory.createTitledBorder("Food Stock"));

    itemLabelArray = (JLabel[]) Array.newInstance(JLabel.class, 15);
    codeLabelArray = (JLabel[]) Array.newInstance(JLabel.class, 15);
    priceLabelArray = (JLabel[]) Array.newInstance(JLabel.class, 15);
    quantityLabelArray = (JLabel[]) Array.newInstance(JLabel.class, 15);

    for (int i = 0; i < 15; i++) { // Maximum No. of Food Item Slots is 15
      itemLabelArray[i] = new JLabel();
      codeLabelArray[i] = new JLabel();
      priceLabelArray[i] = new JLabel();
      quantityLabelArray[i] = new JLabel();

      itemPanel.add(itemLabelArray[i]);
      itemPanel.add(codeLabelArray[i]);
      itemPanel.add(priceLabelArray[i]);
      itemPanel.add(quantityLabelArray[i]);
    }

    itemList = machine.getFoodStocks(); // Get the list of Food Items from the Vending Machine &
    Enumeration e = itemList.elements(); // Store it in the Enumeration

    for (int i = 0;
        e.hasMoreElements();
        i++) { // Store the Items from Enumeration to the ConsumerUI Variables
      VendingMachine.FoodStock stock = (VendingMachine.FoodStock) e.nextElement();
      FoodItem item = stock.item;

      itemLabelArray[i].setText(item.getDescription());

      Integer code = item.getItemCode();
      String str = code.toString();
      codeLabelArray[i].setText("Item Code: " + str);

      Double price = item.getPrice();
      String str1 = price.toString();
      priceLabelArray[i].setText("Price: " + str1);

      Integer quant = machine.GetQuantity(code);
      String str2 = quant.toString();
      quantityLabelArray[i].setText("Quantity: " + str2);
    }

    container1.add(itemPanel);

    // displayPanel
    displayPanel = new JPanel(new FlowLayout());
    displayLabel = new JLabel(display);
    displayPanel.add(displayLabel);
    displayPanel.setBorder(BorderFactory.createTitledBorder("Display Screen"));

    container1.add(displayPanel);

    // actionPanel1 = Consumer Operations Panel
    actionPanel1 = new JPanel(new GridLayout(0, 1));
    actionPanel1.setBorder(BorderFactory.createTitledBorder("Consumer Operations"));

    // actionPanel1 = subPanel1 + subPanel2  + subPanel3

    // subPanel1
    subPanel1 = new JPanel(new FlowLayout());
    buyItem = new JRadioButton("Buy a Food Item");
    acceptLabel = new JLabel(accept);
    codeText = new JTextField(10);

    subPanel1.add(buyItem);
    subPanel1.add(acceptLabel);
    subPanel1.add(codeText);

    actionPanel1.add(subPanel1);

    // subPanel2
    subPanel2 = new JPanel(new FlowLayout());
    displayNutri = new JRadioButton("Display Nutritional Info");
    acceptLabel1 = new JLabel(accept);
    codeText1 = new JTextField(10);
    ok3 = new JButton("Display"); // for enter itemCode

    subPanel2.add(displayNutri);
    subPanel2.add(acceptLabel1);
    subPanel2.add(codeText1);
    subPanel2.add(ok3);

    actionPanel1.add(subPanel2);

    // subPanel3
    subPanel3 = new JPanel(new FlowLayout());
    querySuggest = new JRadioButton("Query Suggestion of Food Items");
    calorieLabel = new JLabel("Maximum Calorie Limit");
    calorieText = new JTextField(10);
    ok4 = new JButton("Display");

    subPanel3.add(querySuggest);
    subPanel3.add(calorieLabel);
    subPanel3.add(calorieText);
    subPanel3.add(ok4);

    actionPanel1.add(subPanel3);

    container1.add(actionPanel1);

    // actionPanel2 - H/W Slots = actionPanel2 + dispatchPanel
    actionPanel2 = new JPanel(new FlowLayout());
    actionPanel2.setBorder(BorderFactory.createTitledBorder("Hardware Slots"));
    enterLabel = new JLabel(enterAmount);
    amountText = new JTextField(10);
    buy = new JButton("BUY");
    cancel = new JButton("Cancel");
    changeLabel = new JLabel(change);
    changeText = new JTextField(10);
    ok1 = new JButton("Collect Change");

    actionPanel2.add(enterLabel);
    actionPanel2.add(amountText);
    actionPanel2.add(buy);
    actionPanel2.add(cancel);
    actionPanel2.add(changeLabel);
    actionPanel2.add(changeText);
    actionPanel2.add(ok1);

    // Dispatch Panel
    dispatchPanel = new JPanel(new FlowLayout());
    dispatcherLabel = new JLabel(dispatcher);
    ok2 = new JButton("Collect Item");

    dispatchPanel.add(dispatcherLabel);
    dispatchPanel.add(ok2);

    actionPanel2.add(dispatchPanel);

    container1.add(actionPanel2);

    // Exit Panel
    exitPanel = new JPanel(new FlowLayout());
    exit = new JButton("Back to Main Menu");
    exitPanel.add(exit);

    container1.add(exitPanel);

    // Registering the components to the Event Handlers
    // Register Buy button to Event Handler
    BuyHandler BHandler = new BuyHandler();
    buy.addActionListener(BHandler);

    // Register button of cancel to Event Handler
    CancelHandler CHandler = new CancelHandler();
    cancel.addActionListener(CHandler);

    // Register RadioButton of 'Buy Item' to Event Handler
    BuyRadioHandler BRHandler = new BuyRadioHandler();
    buyItem.addActionListener(BRHandler);

    // Register RadioButton of 'Display Nutritional Info' to Event Handler
    NutriRadioHandler NutriHandler = new NutriRadioHandler();
    displayNutri.addActionListener(NutriHandler);

    // Register RadioButton of 'Query Suggestion' to Event Handler
    QueryRadioHandler QueryHandler = new QueryRadioHandler();
    querySuggest.addActionListener(QueryHandler);

    // Register Button for 'Display Nutritional Info' to Event Handler
    DisplayNutriHandler DNHandler = new DisplayNutriHandler();
    ok3.addActionListener(DNHandler);

    // Register Button for 'Query Suggestion' to Event Handler
    DisplayNutriHandler DNHandler1 = new DisplayNutriHandler();
    ok4.addActionListener(DNHandler1);

    // Register Button for 'Back to Main Menu' to Event Handler
    MainMenuHandler1 MMHandler1 = new MainMenuHandler1();
    exit.addActionListener(MMHandler1);

    // Register Button for 'Collect Change' to Event Handler
    CollectChangeHandler CCHandler = new CollectChangeHandler();
    ok1.addActionListener(CCHandler);

    // Register Button for 'Collect Food Item' to Event Handler
    CollectItemHandler CIHandler = new CollectItemHandler();
    ok2.addActionListener(CIHandler);
  }
Example #25
0
 public void categorySort() {
   Collections.sort(foodItems, FoodItem.getCategoryComparator());
   howSorted = 0;
 }
Example #26
0
 public static void main(String[] args) {
   FoodItem mixedVegCurry = new FoodItem();
   mixedVegCurry.setName("Mixed Vegetable Curry");
   mixedVegCurry.setSpicynessLevel(EnumSpicynessLevel.EXTRA_HOT);
 }
 private void displayStepImage() {
   int imageResource =
       getResources().getIdentifier(foodItem.getCurrentStepImage(), "drawable", getPackageName());
   Drawable stepImage = getResources().getDrawable(imageResource);
   trainingLayout.setBackground(stepImage);
 }