Jobs[] job = new Jobs[100];
becuase i have a Jobs class that stores an arrival number, jobId, priority and length information
and then find a way to put that into a priority queue so that it can sorted by highest priority...
would it be easier to just scan the file into the priority queue and if so how do i implement the Jobs class so that it knows how to display and store the information correctly. Please help. My coding looks like this:
/*************************************************
*
************************************************/
import java.io.*;
import java.util.Scanner;
import java.util.*;
//this is my Job class that lists my jobId, length, priority and arrival
class Jobs{
public String jobId;
public int length;
public int priority;
public int arrival;
public Jobs(int arrival,String jobId, int priority, int length)
{
this.jobId = jobId;
this.length = length;
this.priority = priority;
this.arrival = arrival;
}
public Jobs(int priority)
{
this.priority = priority;
}
//set and get job Id character
public void setJobId(String jobId)
{
this.jobId = jobId;
}
public String getJobId()
{
return jobId;
}
//set and get job length
public void setLength(int length)
{
this.length = length;
}
public int getLength()
{
return length;
}
//set and get priority
public void setPriority(int priority)
{
this.priority = priority;
}
public int getPriority()
{
return priority;
}
//set and get arrival
public void setArrival(int arrival)
{
this.arrival = arrival;
}
public int getArrival()
{
return arrival;
}
//String to display job id, length, priority and arrival number
public String toString()
{
return jobId + "\t" + length + "\t" + priority + "\t" + arrival;
}
}
// this is my main class
class Main{
public static void main (String[] args) throws IOException{
int x;
int j = 0;
//reading in the information from the file
File file = new File("REVORD.DAT");
FileReader inputFile = new FileReader(file);
Scanner scan = new Scanner(file);
//creating the array to hold the information
Jobs[] job = new Jobs[100];
PriorityQueue queue = new PriorityQueue();
while(scan.hasNext())
{
}
System.out.println("Before Priority Order: ");
//scanning in the file into the array by adding the elements to the queue
while(scan.hasNext())
{
queue.addElement(job);
}
//Removing the elements from the queue in the priority order
System.out.println("Put in Priority Order: ");
while(!queue.isEmpty())
{
System.out.println(queue.removeNext()+ " ");
}
System.out.println();
}
}

New Topic/Question
Reply




MultiQuote







|