I want to create a class that simulates registers of a market and the project requires that after the user gives us how many registers he wants , he must give a string in the form below:
for exaple : 0 0 0 1 1 1 2 2 2 3 3 5 5 6 6
which means that 3 customers entered the store at monent 0 , 3 customers entered the store at moment 1 etc.
Here is my code:
import java.util.Scanner;
import java.io.*;
public class QueueSimulation
{
public static void main(String[] args)
{
int a;
int i = 0;
String input;
Scanner s = new Scanner(System.in);
int A[] = new int[10000];
System.out.println("This programs simulates a queue of customers at registers.");
System.out.println("Enter the number of registers you want to simulate:");
a = s.nextInt();
while(a==0 || a <0){
System.out.println("0 registers or no registers is invalid. Enter again: ");
a = s.nextInt();
}
int fifo[] = new int[a];
System.out.println("Enter how many customers enter per second.For example: 0 0 1 1 2 2 2 3 3.
Enter : ");
input = s.nextLine();
while(s.hasNext()){
while(s.hasNextInt()){
A[i] = s.nextInt();
i++;
}
s.close();
}
s.close();
}
}
The code compiles fine , but when i run it, something goes very wrong with the 2 while loops and the programs nevers end or stop. Complile if you have the time and you will understand. I dont know maybe i placed the close() method somewhere wrong? Please help.