Question: import java.io.File; import java.util.Scanner; import java.io.FileNotFoundException; public class AdvRoundRobinSimulation { private final static int TIME_SLICE = 10; private final static boolean VERBOSE_MODE = true; private
| import java.io.File; | |
| import java.util.Scanner; | |
| import java.io.FileNotFoundException; | |
| public class AdvRoundRobinSimulation { | |
| private final static int TIME_SLICE = 10; | |
| private final static boolean VERBOSE_MODE = true; | |
| private final static boolean READ_FROM_FILE = false; // Read instructions from file or stdin | |
| private static class Instruction { | |
| private String name; | |
| private int time; | |
| private int duration; | |
| private Instruction(String name, int time, int duration) { | |
| // to do | |
| } | |
| public String getName() { | |
| //to do | |
| } | |
| public int getTime() { | |
| //to do | |
| } | |
| public int getDuration() { | |
| // to do | |
| } | |
| public String toString() { | |
| // to do | |
| } | |
| } | |
| private static SinglyLinkedList getInstructionsList() throws FileNotFoundException { | |
| Scanner scnr; | |
| if (READ_FROM_FILE) { | |
| scnr = new Scanner(System.in); | |
| System.out.println("Enter instruction filename to be read:"); | |
| String filename = scnr.nextLine(); // Get filename from stdin | |
| File instructionFile = new File(filename); | |
| scnr = new Scanner(instructionFile); // Scanner to read file input stream. | |
| } | |
| else { | |
| scnr = new Scanner(System.in); | |
| System.out.println("Enter instructions terminated with the DONE instruction"); | |
| } | |
| SinglyLinkedList instructions = new SinglyLinkedList(); | |
| boolean done = false; // Sentinel for the DONE instruction | |
| while (scnr.hasNextLine() && !done) { // Until we reach the EOF | |
| String next = scnr.next(); | |
| if (next.compareTo("AT") == 0) { | |
| int time = scnr.nextInt(); | |
| if (scnr.next().compareTo("ADD") == 0) { | |
| String name = scnr.next(); | |
| int duration = scnr.nextInt(); | |
| Instruction newInstruction = new Instruction(name, time, duration); | |
| instructions.addLast(newInstruction); | |
| } | |
| else | |
| throw new RuntimeException("Instruction format invalid in "); | |
| } | |
| else if (next.compareTo("DONE") == 0) // Done instruction | |
| done = true; | |
| else | |
| throw new RuntimeException("Instruction format invalid in "); | |
| } | |
| scnr.close(); | |
| return instructions; | |
| } | |
| private static int scheduleReadyProcesses(SinglyLinkedList instructionList, | |
| CircularlyLinkedList currentProcessList, | |
| int currentSimulationTime, | |
| int totalProcesses) { | |
| SinglyLinkedList toDelete = new SinglyLinkedList(); | |
| int newProcesses = 0; | |
| for (int i = 0; i < instructionList.length(); i++) { | |
| Instruction curInstruction = instructionList.get(i); | |
| if (curInstruction.time <= currentSimulationTime) { | |
| newProcesses++; | |
| Process p = new Process(curInstruction.getName(), curInstruction.getDuration()); | |
| currentProcessList.addLast(p); | |
| if (VERBOSE_MODE) | |
| System.out.printf("@%05d Added new Process %s ", currentSimulationTime, p.toString()); | |
| toDelete.addFirst(i); | |
| } | |
| } | |
| while (!toDelete.isEmpty()) | |
| instructionList.delete(toDelete.removeFirst()); | |
| return newProcesses; | |
| } | |
| private static void executeNextProcess(CircularlyLinkedList processList) { | |
| //to do | |
| } | |
| public static void main(String[] args) throws FileNotFoundException { | |
| System.out.println("Round Robin Simulation - Joseph Araujo, Munad Hassan, Jeffrey Knutsen, Zain Nenad "); | |
| SinglyLinkedList instructionList = getInstructionsList(); // Get instructions from file | |
| CircularlyLinkedList processList = new CircularlyLinkedList(); // No current processes | |
| int simulationTime = 0; | |
| int sliceCount = 0; | |
| int processNum = 0; // Total number of processes | |
| while(!processList.isEmpty() || !instructionList.isEmpty()) { // While we have processes or instructions left | |
| processNum += scheduleReadyProcesses(instructionList, processList, simulationTime, processNum); // Schedule processes that are ready to start | |
| executeNextProcess(processList); // Execute the next process for TIME_SLICE ms | |
| simulationTime += TIME_SLICE; // Update total execution time | |
| sliceCount++; | |
| if (VERBOSE_MODE) System.out.printf("@%05d %s ", simulationTime, processList); | |
| } | |
| System.out.printf(" Simulation ended at %05d. %d Processes were completed in %d time slices. ", simulationTime, processNum, sliceCount-1); | |
| } | |
| } I need help with he "to do" parts |
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
