Hi there, I'm working on a 'queue program' which will queue 30 job numbers(case 1) between 1 and 30, validated, in an array, display the array , (case 3) and remove a number from the back of the queue.(case 2)
I have the display array and remove from front of queue bits working but I'm struggling to figure out how I'm supposed to have the array values entered 1 at a time and then break back to the switch and case menu.
public static void fillArray(int[] arrayIn){ //filling array code, fills arrayIn with values
Scanner sc = new Scanner (System.in);
System.out.print("Please enter a job number to the queue");
System.out.println(" \r\n ");
if(arrayIn[0]==0 && arrayIn[29]==0)
{ //if 2
for (int i = 0; i < arrayIn.length; i=i+1)
{ //for 1
System.out.print("enter value "); //get input for values..
int value=sc.nextInt();
if (value>0 && value <31)
{
arrayIn[i] = value;
}
else
{
System.out.println("Invalid Number, must be between 1 and 30 inclusive");
}
}
}
else if(arrayIn[0]!=0 && arrayIn[29]!=0)
{
System.out.println("Queue is full, please use menu option 2");
}
}
What ideally would be happening here is that instead of entering 30 at once, once the first value is entered, it would break back to the switch and case, and then the next time that case 1 was entered it would do the same except enter to arrayIn[1] instead of arrayIn[0], and so on until the array is full.
If you need me to post the other program code let me know.
This is probably ridiculously simple and I'm missing something obvious but I'm new in Java so go easy ;).
Cheers, Nick.