Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having two things with my code and if anyone can help me with those. This i

ID: 665098 • Letter: I

Question

I'm having two things with my code and if anyone can help me with those. This is a queue FIFO on java. First my printerwriter is not going through the csis.txt because i get some sort of null error that i cannot figure out why though. Second my output is not correctly doing the arrival and departure right under event. Same goes for the lowest level queue.

This is what the output should display

Here are my codes

Explanation / Answer

import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class Driver { public static void main(String[] args) throws IOException { PrintWriter pw = new PrintWriter(new FileWriter("csis.txt")); MFQ mfq = new MFQ(pw); mfq.getJobs(); mfq.outputHeader(); mfq.runSimulation(); mfq.outStats(); pw.close(); } } //MFQ Class import java.io.*; import java.util.Scanner; public class MFQ extends Driver { private PrintWriter pw; ObjectQueue que = new ObjectQueue(); CPU cpu = new CPU(pw); Scanner read = new Scanner(new File("mfq.txt")); Job job = new Job(pw, read); public MFQ(PrintWriter pw) throws IOException { this.pw = pw; } /** * * @throws IOException */ public void getJobs() throws IOException { Job job = new Job(pw, read); if (!read.hasNextLine()) { } else { job.job(read); que.insert(job.jobList()); //Inserts jobList() which is cast up to an Object. This is the Queue that houses all jobs, //confirmed by my outStats() method. getJobs(); } } //Recursive call. /** * @param- calls header */ public void outputHeader() { System.out.println("Event " + "System Time " + "PID " + "CPU Time Needed " + "Total Time in System " + "Lowest Level Queue "); pw.println("Event " + "System Time " + "PID " + "CPU Time Needed " + "Total Time in System " + "Lowest Level Queue "); } //System.out.println(" Add Process Work Time: ID: Time:");} /** * @param - calls simulations * @throws IOException */ public void runSimulation() throws IOException { if (!que.isEmpty()) { cpu.doWork(que.remove()); System.out.print(cpu.getTime()); if (!que.isEmpty()) System.out.print(que.query()); else ; runSimulation(); } } /** * @param- calls out stats */ public void outStats() { if (!que.isEmpty()) { System.out.println(que.query()); pw.println(que.remove()); outStats(); } } } //ObjectQueue public class ObjectQueue implements ObjectQueueInterface { private Object[] item; private int front; private int rear; private int count; /** * @param- ObjectQueue * @return- */ public ObjectQueue() { item = new Object[1]; front = 0; rear = -1; count = 0; } /** * * @return- new object */ public boolean isEmpty() { return count == 0; } /** * * @return - 0 */ public boolean isFull() { return count == item.length; } /** * @return- count */ public void clear() { item = new Object[1]; front = 0; rear = -1; count = 0; } /** * * @param o */ public void insert(Object o) { if (isFull()) resize(2 * item.length); rear = (rear+1) % item.length; item[rear] = o; ++count; } /** * * @return- temp */ public Object remove() { if (isEmpty()) { System.out.println("Queue Underflow"); System.exit(1); } Object temp = item[front]; item[front] = null; front = (front+1) % item.length; --count; if (count == item.length/4 && item.length != 1) resize(item.length/2); return temp; } /** * * @return- item[front] */ public Object query() { if (isEmpty()) { System.out.println("Queue Underflow"); System.exit(1); } return item[front]; } /** * * @param- size */ private void resize(int size) { Object[] temp = new Object[size]; for (int i = 0; i 0) { quantum++; workTime--; cpuTime++; } else if(workTime == 0) { System.out.print("Departure " + cpuTime + " " + quantum + q1.remove()); pw.print("Departure " + cpuTime + " " + quantum + q1.remove()); workTime = job.workTime(); quantum = 0; } else { q2.insert(q1.remove()); System.out.print("Arrival " + cpuTime + " " + quantum); pw.print("Arrival " + cpuTime + " " + quantum); quantum = 0; queueTwo(); } } /** * @param - queueTwo * @return- queueThree */ public void queueTwo(){ if(quantum < 4 && workTime > 0) { quantum++; workTime--; cpuTime++;} else if(workTime == 0) { System.out.print("Departure " + cpuTime + " " + quantum + q2.remove()); pw.print("Departure " + cpuTime + " " + quantum + q2.remove()); workTime = job.workTime(); quantum = 0; } else { q3.insert(q2.remove()); System.out.print("Arrival " + cpuTime + " " + quantum); pw.print("Arrival " + cpuTime + " " + quantum); quantum = 0; queueThree(); } } /** * @param- queueThree * @return- queueFour */ public void queueThree() { if(quantum < 8 && workTime > 0) { quantum++; workTime--; cpuTime++; } else if(workTime == 0) { System.out.print("Departuret" + cpuTime + " " + quantum + q3.remove()); pw.print("Departuret" + cpuTime + " " + quantum + q3.remove()); workTime = job.workTime(); quantum = 0; } else { q4.insert(q3.remove()); System.out.print("Arrival " + cpuTime + " " + quantum); pw.print("Arrival " + cpuTime + " " + quantum); quantum = 0; queueFour();} } /** * @param- queueFour */ public void queueFour() { if(quantum < 16 && workTime > 0) { quantum++; workTime--; cpuTime++; } else if(workTime == 0) { System.out.print("Departure " + cpuTime + " " + quantum + q4.remove()); pw.print("Departure " + cpuTime + " " + quantum + q4.remove()); quantum = 0; workTime = job.workTime(); } else { q4.insert(q4.remove()); System.out.print("Arrival " + cpuTime + " " + quantum); pw.print("Arrival " + cpuTime + " " + quantum); System.out.print(workTime); System.out.println(q4.query()); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote