Skip to content

Commit

Permalink
Burger inicial
Browse files Browse the repository at this point in the history
  • Loading branch information
jandion committed Apr 25, 2024
1 parent 577030c commit 7d18026
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Concurrencia/src/burger/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package burger;

/**
* 1. Clientes recogen productos de 1 en 1
* 2. Clientes recogen todo el pedido de golpe
* 3. Se incorporan las patatas como segundo producto
* 4. La bandeja de salida tiene un tamaño limitado
*/

public class Main {

public static final String CLEAR = "\n".repeat(50);

public static void main(String[] args) {

Pedido pedido = Pedido.pedidoAleatorio();

System.out.println(pedido);

pedido.hamburguesasRecogidas++;
System.out.println(CLEAR);
System.out.println(pedido);

}
}
37 changes: 37 additions & 0 deletions Concurrencia/src/burger/Pedido.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package burger;

public class Pedido {
public static final String HAMBURGUESA = "🍔";
public static final String PATATAS = "🍟";
public static final int MAX_ITEMS = 4;

public int hamburguesas, hamburguesasRecogidas;
public int patatas, patatasRecogidas;
public long creacion;

public static Pedido pedidoAleatorio() {
int nHamburguesas = (int) (1 + Math.random()*MAX_ITEMS);
int nPatatas = (int) (Math.random()*MAX_ITEMS);
return new Pedido(nHamburguesas, nPatatas);
}

public Pedido(int hamburguesas, int patatas) {
this.hamburguesas = hamburguesas;
this.patatas = patatas;
this.creacion = System.currentTimeMillis();
}

@Override
public String toString() {
String res = "----------------\n";
res += "Creado hace %3s segs\n".formatted((System.currentTimeMillis()-creacion)/1000);
res += "----------------\n";
res += "Hamburguesas: "+ HAMBURGUESA.repeat(hamburguesas) + "\n";
res += "Recibidas: "+ HAMBURGUESA.repeat(hamburguesasRecogidas) + "\n";
res += "----------------\n";
res += "Patatas: "+ PATATAS.repeat(patatas) + "\n";
res += "Recibidas: "+ PATATAS.repeat(patatasRecogidas) + "\n";
res += "----------------\n";
return res;
}
}
Empty file added examen.md
Empty file.

0 comments on commit 7d18026

Please sign in to comment.