I have the following exercise:
A restaurant has commissioned us an application to place customers in
your tables. On a table you can seat from 0 (empty table) to 4 people
(full table). When a customer arrives, they are asked how many they are. For now
the program is not prepared to place groups larger than 4, therefore,
If a client says for example that they are a group of 6, the program will give the
message "Sorry, we do not support groups of 6, make groups of 4
maximum people and try again. " For the group that arrives,
always look for the first free table (with 0 people). If there are no tables
free, search where there is a gap for the whole group, for example if the
group is two people, you can place where there is one or two people.
Initially, the tables are loaded with random values between 0 and 4. Each
Once new customers feel they must show the status of the tables.
Groups can not be broken even if there are enough loose holes.
The problem I have is that I look for an empty table worth, compare and enter the number of people .... at that time I was supposed to stop looking for empty tables, but the program keeps looking for empty tables and people enter , I can not find a way to get the program out of the cycle or stop looking for tables when I have already found the first ... I hope to make myself understood.
public static void main(String[] args) {
Scanner entrada = new Scanner (System.in);
int mesa[] = {1,2,3,4,5,6,7,8,9,10};
int ocupacion [] = {3,2,0,2,4,1,0,2,1,1};
int cant;
int aux;
do{
System.out.println("Bienvenidos a mi restaurante");
System.out.println("Cuantos son?: (Introduzca -1 para salir del programa)");
cant = entrada.nextInt();
if (cant == -1){
break;
}else if (cant >4 ){
System.out.println("Lo sentimos no admitimos grupos de:" + cant);
} // Esto se puede utilizar mas adelante
} while(cant>4);
aux = cant;
while (aux>0){
int j = 0;
for (int i = 0; i < 10; i++) {
if(ocupacion [i] ==0){
System.out.println("Por favor, sientese en la mesa numero: "+ mesa[j]);
ocupacion [i] = cant;
break;
}
/* CODIGO INCOMPLETO POR LOS MOMENTOS UwU
else if ((ocupacion [i] + cant) < 5){break;
System.out.println("Lo sentimos, tendra que compartir mesa: ");
ocupacion [i] = ocupacion [i] + cant;
break;
}*/
j++;
}
}
for (int i = 0; i < 10; i++) {
System.out.print(ocupacion [i]);
}
}