user2934779
user2934779

Reputation: 23

Queues of Arrays Java

I'm working on a program that orders jobs for three different people, so I used queues because the jobs need to be done first in, first out. The jobs are arrays storing three different strings. This is the relevant code I have at the moment.

Queue<String[]> MMT1Jobs  = new LinkedList<String[]>();
Queue<String[]> MMT2Jobs  = new LinkedList<String[]>();
Queue<String[]> MMT3Jobs  = new LinkedList<String[]>();
//job array layout should look like this [registration number][grid reference][who is assign to the job]
String[] MMT1CurrentJob = new String[3];
String[] MMT2CurrentJob = new String[3];
String[] MMT3CurrentJob = new String[3];
String[] MMT1LastJob = new String[3];
String[] MMT2LastJob = new String[3];
String[] MMT3LastJob = new String[3];
String[] justScanned = new String[3];
//check if there is any Jobs open
File jobsOpenFile = new File("JOBS-OPEN.txt");
if(jobsOpenFile.exists())
{
  //File exists
  Scanner jobsFile = new Scanner(jobsOpenFile);
  while(jobsFile.hasNext == true)
  {
    justScanned[1] = jobsFile.next();//registration number
    justScanned[2] = jobsFile.next();//grid reference
    justScanned[3] = jobsFile.nextLine();//who is assigned and end of line
    //assign who get what jobs
    if(justScanned[3].equals("1"))
    {
      MMt1Jobs.add(justScanned[]);//error here
    }
    else if(justScanned[3].equals("2"))
    {
      MMt2Jobs.add(justScanned[]);//error here
    }
    else
    {
      MMt3Jobs.add(justScanned[]);//error here
    }
  }
}

I'm currently getting "error: '.class' expected" on the lines that I've marked. Sorry if this is a simple fix but I'm new to java. Thanks in advance.

Upvotes: 2

Views: 10569

Answers (2)

Juned Ahsan
Juned Ahsan

Reputation: 68715

I believe you don't need the array brackets([]) in your errornous statements:

  MMt1Jobs.add(justScanned[]);//error here

replace this with

  MMt1Jobs.add(justScanned)

No need for that extra [].

[] is a syntax part of array declaration time to specify length of array.

Therefore, you need not use it while adding the array to a list. Just use variable name.

Upvotes: 6

Alex
Alex

Reputation: 1110

May be a very silly thing to point out, but if this was copy-pasted then shouldn't your "MMt1Jobs" be "MMT1Jobs", with a capital "t"?

Upvotes: 0

Related Questions