I wrote this code which takes a .txt file and scans it. Each line represents a separate process with its attributes. I need to be able to loop through each line of the .txt file and assign the different values to the process's fields.
Here's my process class:
public class Process {
private String name;
private int arrive_time= 0;
private int burst_time = 0;
private int remain_time = 0;
public Process (String name, int arr_time, int bur_time) {
this.arrive_time = arr_time;
this.burst_time = bur_time;
this.remain_time = burst_time;
this.name = name;
}
public int getArrTime() {return arrive_time;}
public int getBurTime() {return burst_time;}
public int getRemTime() {return remain_time;}
public String getName() {return name;}
public void decRemTime() {this.remain_time--;}
}
Here's my .txt file:
P1 0 8
P2 1 4
P3 2 9
P4 3 3
END 4 9999
p1 is supposed to be assigned to the name variable of the first process. 0 is the arrival time. and 8 is the burst time. Then we move onto the next line and do the same for a new process that we will be creating every time I move to a new line in the .txt
Here's my code for assigning things:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class Test {
public static void main(String[] args) {
//Priority queue for storing the initialized processes
PriorityQueue<Process> prq = new PriorityQueue<Process>(5, new Comparator<Process> () {
@Override
public int compare(Process p1, Process p2) {
return p1.getArrTime() - p2.getArrTime();
}
});
BufferedReader br = null;
String line;
try {
br = new BufferedReader(new FileReader("C:\\Users\\Veni\\Desktop\\test\\test.txt\\"));
}
catch (FileNotFoundException fnfex) {
System.out.println(fnfex.getMessage() + "File not found");
System.exit(0);
}
try {
int localProcessIndex = 0;
/* Count number of lines in .txt and store number in localProcessIndex.
* Then declare exactly that many processes.
*
* Then move to the loop below and start reading each line's values
* and start initialising the processes with those values.
*
* Then move all the processes to the prq priority queue.
*/
while((line = br.readLine()) != null) {
//Process localProcessIndex = new Process(line.split);
//System.out.println(line);
}
}
catch(IOException ioex) {
System.out.println(ioex.getMessage() + "Error reading");
}
SPN spn = new SPN(prq);
spn.SPN_ALG();
}
}