Exemple #1
0
  public double preco() {
    double calc = 0.0;

    for (Ingrediente ingredientes : this.ingredientes) {
      calc += ingredientes.preco();
    }

    return calc;
  }
Exemple #2
0
  public boolean guardarRecetaModoAvanzado(
      ArrayList<Ingrediente> ingredientes, ArrayList<Paso> pasos, String nombre) {
    // Create a factory

    File file = new File(rutaAlmacenamientoExterno + "recetas.xml");
    if (!file.exists()) crearArchivo("recetas.xml", "recetas");

    Document doc = getDoc("recetas.xml");
    if (doc != null) {

      // Compruebo que no hay ninguna lista con el mismo nombre
      NodeList recetas = doc.getElementsByTagName("receta");
      for (int i = 0; i < recetas.getLength(); i++) {
        Element current = (Element) recetas.item(i);
        if (current.getAttribute("nombre").equals(nombre)) return false;
      }
      Element receta = doc.createElement("receta");
      receta.setAttribute("nombre", nombre);

      // Creo y añado los ingredientes
      Element ingredientesRoot = doc.createElement("ingredientes");

      for (int i = 0; i < ingredientes.size(); i++) {
        Ingrediente ing = ingredientes.get(i);
        Element ingredienteChild = doc.createElement("ingrediente");
        ingredienteChild.setAttribute("nombre", ing.getNombre());
        ingredienteChild.setAttribute("cantidad", ing.getCantidad());
        ingredientesRoot.appendChild(ingredienteChild);
      }
      receta.appendChild(ingredientesRoot);

      // Creo y añado la elaboración

      Element elaboracionRoot = doc.createElement("elaboracion");
      elaboracionRoot.setAttribute("mode", "advanced");
      for (int i = 0; i < pasos.size(); i++) {
        Paso p = pasos.get(i);
        Element paso = doc.createElement("paso");
        paso.setAttribute("numero", p.getNumber());
        if (p.getPath() != null) {
          paso.setAttribute("path", p.getPath());
        }
        paso.setTextContent(p.getDescripcion());
        elaboracionRoot.appendChild(paso);
      }

      receta.appendChild(elaboracionRoot);

      // añado la receta al root element
      doc.getDocumentElement().appendChild(receta);

      return saveDoc("recetas.xml", doc);
    }

    return false;
  }
  public View getView(int position, View convertView, ViewGroup parent) {
    final IngredientesDataSource ingS = new IngredientesDataSource(context);
    ingS.open();

    // First let's verify the convertView is not null
    if (convertView == null) {
      // This a new view we inflate the new layout
      LayoutInflater inflater =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = inflater.inflate(R.layout.ingrediente_list, parent, false);
    }
    // Now we can fill the layout with the right values
    TextView tv = (TextView) convertView.findViewById(R.id.ingredienteimportante);
    final Ingrediente r = inglist.get(position);
    tv.setText(r.get_nombre());
    return convertView;
  }
Exemple #4
0
 public static void main(String[] args) {
   Scanner sc = new Scanner();
   while (true) {
     int p = sc.nextInt();
     if (p == 0) return;
     for (int i = 0; i < p; i++) {
       String nombre = sc.nextLine();
       int numero = sc.nextInt();
       actual = new Producto(nombre, numero);
       for (int j = 0; j < numero; j++) {
         String[] pedazos = sc.nextLine().split("\\s+");
         String nActual = pedazos[0];
         String posible = pedazos.length == 1 ? null : pedazos[1];
         if (posible == null) actual.ingredientes[j] = new Ingrediente(nActual, i);
         else
           actual.ingredientes[j] =
               new Ingrediente(
                   nActual, i, Integer.parseInt(posible.substring(0, posible.length() - 1)));
       }
       productos[i] = actual;
       for (int a = 0; a < 110; a++)
         for (int j = 0; j < 110; j++) for (int k = 0; k < 110; k++) dp[a][j][k] = null;
       posible(0, 100, 0);
       for (int j = 0; j < numero; j++)
         actual.mapa.put(actual.ingredientes[j].nombre, actual.ingredientes[j]);
     }
     int q = sc.nextInt();
     TreeSet<Integer> resultado = new TreeSet<Integer>();
     for (int query = 0; query < q; query++) {
       String cual = sc.next();
       boolean most = cual.equals("most");
       String ingrediente = sc.next();
       ArrayList<Ingrediente> enOrden = new ArrayList<Ingrediente>();
       for (int i = 0; i < p; i++)
         if (productos[i].mapa.containsKey(ingrediente))
           enOrden.add(productos[i].mapa.get(ingrediente));
         else enOrden.add(new Ingrediente(ingrediente, i, 0));
       if (most) {
         Collections.sort(enOrden, new Menor());
         Ingrediente ultimo = enOrden.get(enOrden.size() - 1);
         resultado.clear();
         for (int i = ultimo.minimo; i <= ultimo.maximo; i++) {
           for (Ingrediente in : enOrden) if (in.cumple(i)) resultado.add(in.producto);
         }
         System.out.print(productos[resultado.pollFirst()].nombre);
         while (!resultado.isEmpty())
           System.out.print(" " + productos[resultado.pollFirst()].nombre);
         System.out.println();
       } else {
         Collections.sort(enOrden, new Mayor());
         Ingrediente ultimo = enOrden.get(0);
         resultado.clear();
         for (int i = ultimo.minimo; i <= ultimo.maximo; i++) {
           for (Ingrediente in : enOrden) if (in.cumple(i)) resultado.add(in.producto);
         }
         System.out.print(productos[resultado.pollFirst()].nombre);
         while (!resultado.isEmpty())
           System.out.print(" " + productos[resultado.pollFirst()].nombre);
         System.out.println();
       }
     }
   }
 }