Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto4-CeliaBecerril #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions Caja.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@

class Caja {
private Cliente clienteActual;
private int numeroCaja;
private int numeroItems;

public boolean estaLibre() {

public Caja(int numeroCaja) {
this.numeroCaja = numeroCaja;
this.numeroItems = 0;
}

public void recibe(Cliente cliente) {
public boolean estaLibre() {
return clienteActual == null;
}

public void recibe(Cliente cliente, int numeroItems) {
if (estaLibre()) {
clienteActual = cliente;
this.numeroItems = numeroItems;
} else {
System.out.println("Caja ocupada");
}
}

public void atiende() {

if (!estaLibre()) {

System.out.println("Número de items: " + numeroItems);
clienteActual = null;
numeroItems = 0;
} else {
System.out.println("La caja está libre, no hay clientes para atender.");
}
}

public void verEstado() {

if (!estaLibre()) {

System.out.println("Número de items: " + numeroItems);
} else {
System.out.println("La caja " + numeroCaja + " está libre.");
}
}
}
}
9 changes: 6 additions & 3 deletions CentroComercial.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CentroComercial {
public CentroComercial(){
cajas = new Caja[4];
for (int i = 0; i < cajas.length; i++) {
cajas[i] = new Caja();
cajas[i] = new Caja(i);
}
cola = new Cliente[100];
ultimo = 0;
Expand All @@ -20,7 +20,7 @@ public void recibe(Cliente cliente) {
}

public void actualizar() {
if(ultimo>=0) {
if(ultimo>0) {
deColaACaja();
}
atiendeCajas();
Expand All @@ -31,7 +31,10 @@ private void deColaACaja() {
if (cajas[i].estaLibre()){
Cliente cliente = cola[ultimo];
ultimo--;
cajas[i].recibe(cliente);
cajas[i].recibe(cliente, (int)(Math.random()*10));
}
if (ultimo==0){
break;
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions Cliente.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

class Cliente {


private int cantidadItems;


public Cliente() {
this.cantidadItems = (int)(Math.random() *11)+5;
}

public int cantidadItems() {
return cantidadItems;
}

}
}