I have the following method which takes user input and applies an algorithm to it. However when I try to print the String process_name, stored in the fcfs ArrayList it comes out empty. But the burst_time and arrival_time fields in the same fcfs ArrayList get output to the console exactly as the user inputted the data. Not really sure what could be wrong.
public static void algorithm() {
ArrayList<Process> fcfs = new ArrayList<>();
Scanner scan = new Scanner(System.in);
System.out.println("Process name,CPU Burst Time,Arrival time\n ");
while (!scan.next().equalsIgnoreCase("finish")) {
Process p = new Process();
String pn = "";
String bt = "";
String at = "";
pn = input.nextLine();
bt = input.nextLine();
at = input.nextLine();
System.out.println("Process name, CPU Burst Time, Arrival time\n ");
p.process_name = pn;
p.burstTime = Float.parseFloat(bt);
p.arrivalTime = Float.parseFloat(at);
fcfs.add(p);
}
{
Collections.sort(fcfs, new comp());
}
result(fcfs, fcfs.size(),false)
}
This is the Process class:
class Process {
String process_name;
float burstTime;
float arrivalTime;
float compTime = 0;
boolean status = false;
}