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

Simulate a networked printing facility that can operate with a variable number o

ID: 3623775 • Letter: S

Question

Simulate a networked printing facility that can operate with a variable number of printers. Your simulation should be able to run the printing facility with any number of printers (1, 2, 3, etc.). The point of the simulation is to determine if would be advantageous to stick with just one printer, or upgrade the facility with additional printers - in which case, how many printers would be optimal?
For the sake of keeping the simulation simple, we will assume one new printing job comes in every minute, and print jobs are assigned one of 3 possible priority levels based on the number of pages being printed. Top priority will be granted to all the jobs containing 10 or less pages. Medium priority will be given to all the jobs containing 11-20 pages, and low priority will be given to any jobs with more than 20 pages. When multiple jobs are forced to wait for a printer, all the jobs at the same priority level are held in a FIFO queue to ensure reasonable printing times for all users.
Your simulation will start by reading integer values in a text file.

Required Classes/Methods
(1) public void setUpExperiment(int pagelimit)
is used to generate 100 random print jobs with page counts less than or equal to the value of the limit argument. This method writes each print job (all you need to record is the page count) to a file named simulation.txt.
(2) public void setUpFromExistingData(int pagelimit) is used to read existing data from the “simulation.txt” file. The parameter limit describes the maximal page count for each job in the existing data set.
(3) public int runExperiment(int printers, int t1, int t2) is used to run a single simulation. The argument printers specifies the number of printers to be used in the simulation. The other two arguments specify page count thresholds for the priority queues. If a page count is less than or equal to t1, that job gets the highest priority, and if a page count is greater than t2, that job gets the lowest priority. Page counts less than or equal to t2 and greater than t1 get the middle level priority.

Explanation / Answer

Dear..... Sample code: 1) Random generator = new Random ();
int[] printJobs = new int[100];

for (int i = 0; i < 100; i++) {
printJobs[i] = generator.nextInt (pagelimit) + 1;
}
try {
// Create file
FileWriter fstream = new FileWriter ("simulation.txt");
BufferedWriter out = new BufferedWriter (fstream);

out.write (printJobs[0]);
for (int i = 1; i < 100; i++) {
out.write (", " + printJobs[i]);
}

out.close ();
} catch (Exception e) {}; ------------------------------------------------------------------------------------------------------
3)
Queue<int> high = new LinkedList<int> ();
Queue<int> medium = new LinkedList<int> ();
Queue<int> low = new LinkedList<int> ();

// set up some if statements to sort your inputs
while (!done) {
if (t1 > value)
high.add (value);
else if (value > t2)
low.add (value);
else
medium.add (value);
}
// when you're ready to simulate printing...
while (true) {
if (!high.isEmpty())
high.remove();
else if (!medium.isEmpty())
medium.remove();
else if (!low.isEmpty())
low.remove();
else
break;
}