2021-09-30 20:54:35 +10:00

68 lines
1.8 KiB
Java

import java.util.*;
import java.io.*;
public class P2 {
/**
* COMP2240 Assignment 2 Part 2
* Date:
* Author: Zach S-B
* Student Number: c3262201
*/
private int numOfJobs = 0;
private LinkedList<P2_Jobs> jobList = new LinkedList<P2_Jobs>();
private P2_Printer printer = new P2_Printer();;
/**
* Main. Runs the program
*/
public static void main(String[] args){
P2 system = new P2();
system.run();
}
public void run()
{
//Read file inputs and save to a job list.
readFile("../P2-1in.txt");
//Start the jobs going
for(int i = 0; i<jobList.size(); i++)
{
Thread job = new Thread(jobList.get(i));
job.start();
}
}
/**
* readFile. Reads the file given, creating processes as needed to save details.
* @param fileNameInput address of the file to be read in.
*/
public void readFile(String input)
{
Scanner fileReader; //Scanner to read the file.
File dataInput;// = new File(fileNameInput);
dataInput = new File(input);
//Try and open file. If it works, procede.
try {
fileReader = new Scanner(dataInput);
String line = fileReader.nextLine();
numOfJobs = line.charAt(0) - '0';
for(int i = 0; i< numOfJobs; i++)
{
line = fileReader.nextLine();
jobList.add(new P2_Jobs(line, printer));
}
fileReader.close();
}
//If the file isn't found, throw a hissy fit.
catch (FileNotFoundException e) {
System.out.println("File not found.");
System.exit(0);
//e.printStackTrace(); //Optional, shows more data.
}
}
}