Tengo que hacer un programa Java usando escaneo, cambio y casos en los que puedo agregar un cliente con el comando "agregar" y eliminar un cliente con el comando "eliminar".
El número predeterminado de clientes en cola es 5. Si el número de clientes supera los 8, se imprime "Esta cola es demasiado grande". Si hay menos de 1 cliente, se imprime "No hay nadie en la cola".
Traté de hacer parte del código, pero no tengo idea de qué hacer a continuación.
import java.util.Scanner; public class fronta { public static void main(String[] args) { System.out.println ("This queue has 5 people in it at the moment."); Scanner scan = new Scanner(System.in); boolean x = true; String b = "ADD"; int a = 5; b = scan.nextLine(); while(x){ switch (b) { case "ADD": System.out.println ("This queue has " + a + " people in it at the moment."); b = scan.nextLine(); System.out.println ("This queue is too big"); break; default: case "EXIT": System.out.println("End of simulation."); x = false; break; } } } }Creo que necesitas algo como lo siguiente:
public static void main(String[] args) { boolean isExitRequested = false; int queueSize = 5; System.out.println ("This queue has "+queueSize+" people in it at the moment."); Scanner scan = new Scanner(System.in); while(scan.hasNextLine()){ String input = scan.nextLine(); switch (input){ case "ADD": System.out.println ("This queue has " + queueSize++ + " people in it at the moment."); if (queueSize > 8) { System.out.println("This queue is too big"); } break; case "REMOVE": if (queueSize == 0){ System.out.println("There's nobody in the queue."); } else { queueSize--; } break; case "EXIT": isExitRequested = true; break; default: System.out.println("Unknown input: "+input); } if(isExitRequested) break; } }