Exemplo n.º 1
0
 public void comprar(Producto e) {
   if (numeroTargeta != 0) {
     if (credito > 0) {
       pedido.addProductos(e);
       credito -= pedido.getPrecio();
     } else {
       System.out.println("lo sentimos credito excedido");
     }
   } else {
     pedido.addProductos(e);
   }
 }
Exemplo n.º 2
0
  @Override
  public void run() {
    boolean tieneOrdenes;
    int tiempo;
    int sleepTime;

    while (active) {
      if (!this.getOrdenes().isEmpty()) {
        tieneOrdenes = true;
      } else {
        tieneOrdenes = false;
      }
      try {
        Orden temp = this.ordenes.get(0);
        tiempo = temp.getTiempoTotal();
        finishedOrder = false;
        this.bar.setValue(0);
        sleepTime = tiempo * 10 / 100;
        sleepTime *= 100;
        while (!finishedOrder) {
          if (bar.getValue() != 100) {
            bar.setValue(bar.getValue() + 1);
            try {
              Thread.sleep(sleepTime);
            } catch (Exception e) {
            }
          } else {
            finishedOrder = true;
            break;
          }
        }
        this.ordenes.remove(0);
        int menor = Integer.MAX_VALUE;

        int index = 0;
        for (int i = 0; i < this.ordenesCamion.size(); i++) {
          if (menor > ordenesCamion.get(i).size() && ordenesCamion.get(i).size() != 10) {
            menor = ordenesCamion.get(i).size();
            index = i;
          }
        }
        ordenesCamion.get(index).add(temp);
        this.bar.setValue(0);

      } catch (Exception e) {
      }
    }
  }
Exemplo n.º 3
0
 public String toString() {
   StringBuilder builder = new StringBuilder();
   if (numeroTargeta != 0) {
     builder
         .append("\nCliente: " + nombre)
         .append("\nNumero de Targeta: " + numeroTargeta)
         .append("\nCredito restante: " + credito);
   } else {
     builder.append("\nCliente : " + nombre);
   }
   if (pedido.getNumeroDeProductos() > 0) {
     builder.append("\n" + pedido);
   }
   return builder.toString();
 }