コード例 #1
0
ファイル: CartActivity.java プロジェクト: wusujen/SaS
  /**
   * @param username
   * @return A string of all of the required values of one entity the user has specified
   */
  public static String getStringRDVTotalsFor(String username) {
    List<Person> p = adb.getAllPeopleFor(username);
    List<RecDailyValues> rdvList = new ArrayList<RecDailyValues>();
    if (p != null) {
      for (int i = 0; i < p.size(); i++) {
        RecDailyValues tempRDV = new RecDailyValues(p.get(i));
        rdvList.add(tempRDV);
      }
    } else {
      adb.close();
      return "No one has been added to Cart yet. Please check preferences.";
    }

    adb.close();
    RecDailyValues total = getTotalRDVOf(rdvList);
    return total.returnString();
  }
コード例 #2
0
ファイル: CartActivity.java プロジェクト: wusujen/SaS
  /**
   * @param rdvList
   * @return RecDailyValue Contains all of the totaled values for the group of people the user has
   *     set
   */
  public static RecDailyValues getTotalRDVOf(List<RecDailyValues> rdvList) {

    RecDailyValues total = new RecDailyValues();

    for (int i = 0; i < rdvList.size(); i++) {
      // create a temporary RDV object
      RecDailyValues temp = rdvList.get(i);

      // set all of the properties based on the current and the sum of the
      total.setCalories(total.getCalories() + temp.getCalories());
      total.setProtein((total.getProtein() + temp.getProtein()));
      total.setFat((total.getFat() + temp.getFat()));
      total.setCarbohydrate((total.getCarbohydrate() + temp.getCarbohydrate()));
      total.setFiber((total.getFiber() + temp.getFiber()));
      total.setSugar((total.getSugar() + temp.getSugar()));
      total.setCalcium((total.getCalcium() + temp.getCalcium()));
      total.setIron((total.getIron() + temp.getIron()));
      total.setMagnesium((total.getMagnesium() + temp.getMagnesium()));
      total.setPotassium((total.getPotassium() + temp.getPotassium()));
      total.setSodium((total.getSodium() + temp.getSodium()));
      total.setZinc((total.getZinc() + temp.getZinc()));
      total.setVitC((total.getVitC() + temp.getVitC()));
      total.setVitB6((total.getVitB6() + temp.getVitB6()));
      total.setVitB12((total.getVitB12() + temp.getVitB12()));
      total.setVitA((total.getVitA() + temp.getVitA()));
      total.setVitE((total.getVitE() + temp.getVitE()));
      total.setVitD((total.getVitD() + temp.getVitD()));
      total.setVitK((total.getVitK() + temp.getVitK()));
      total.setFatSat((total.getFatSat() + temp.getFatSat()));
      total.setFatPoly((total.getFatPoly() + temp.getFatPoly()));
      total.setCholesterol((total.getCholesterol() + temp.getCholesterol()));
    }

    return total;
  }