コード例 #1
0
  /**
   * This method returns a hashmap of how many cows, bulls, novillos ...etc there is.
   *
   * @return
   */
  public HashMap<String, Integer> dataForChartEdadesySexo() {
    // Map<String, Integer>
    int vacas = 0;
    int toros = 0;
    int novillos = 0;
    int novillas = 0;
    int crias_f = 0;
    int crias_m = 0;

    ConectorBovino cb = new ConectorBovino();
    ArrayList<Bovino> bovinos = cb.getVivosyNoVendidos();
    String sexo;
    int meses;

    for (Bovino b : bovinos) {
      sexo = b.getSexo();
      if (sexo.equalsIgnoreCase("Hembra")) {
        // es hembra
        meses = getMonthsOld(b.getFecha_nacimiento());
        if (meses >= 24) {
          vacas++;
        }
        if (meses >= 12 && meses < 24) {
          novillas++;
        }
        if (meses < 12) {
          crias_f++;
        }
      } else {
        // es macho
        meses = getMonthsOld(b.getFecha_nacimiento());
        if (meses >= 24) {
          toros++;
        }
        if (meses >= 12 && meses < 24) {
          novillos++;
        }
        if (meses < 12) {
          crias_m++;
        }
      }
    }
    HashMap<String, Integer> map = new HashMap<>();
    map.put("vacas", vacas);
    map.put("toros", toros);
    map.put("novillas", novillas);
    map.put("novillos", novillos);
    map.put("becerras", crias_f);
    map.put("becerros", crias_m);

    return map;
  }
コード例 #2
0
  /**
   * This method return a hashmap with the key representing the bovine race and value the numer of
   * animals that are that race.
   *
   * @return
   */
  public HashMap<String, Integer> chartRaza() {
    HashMap<String, Integer> map = new HashMap<>();
    ConectorBovino cb = new ConectorBovino();
    ArrayList<Bovino> bovinos = cb.getVivosyNoVendidos();

    String r;
    for (Bovino b : bovinos) {
      r = b.getRaza().getNombre();
      if (map.containsKey(r)) {
        Integer get = map.get(r);
        get = get + 1;
        map.put(r, get);
      } else {
        map.put(r, 1);
      }
    }

    return map;
  }