Untitled
user_0846129
plain_text
2 years ago
3.9 kB
5
Indexable
Never
write a comment for each line on what they dpo WHILE processInput is False DO // //Initializing each input process to false, to validate if the user have inputted a process TRY // Check if user enter a valid input for process PRINT "Enter the number of process" // Ask the user for the number of processes SET job ← user input for number of processes // sets the value of job to the input of user for processes SET processInput ← true // sets the value of processInput to true CATCH inputMismatchException // Repeat loop until user enters valid number of processes PRINT " Please enter a WHOLE NUMBER only" END TRY-CATCH END WHILE SET Burst ← ARRAY of double of size job // creates an array of double SET Priority ← ARRAY of integer of size job // creates an array of int FOR i ← 0 to job-1 DO // iterates over each job SET burstInput ← False // set the BurstInput value to false priorityInput ← False // set the priorityInput value to false PRINT "\n------------------------------------- Process " + (i+1) + " ------------------------------------" // printing process number // Loop to ensure inputs a valid Burst value for each process WHILE burstInput is False DO TRY PRINT "Burst Time" // ask user to input burst time SET Burst[i] ← user input for Burst Time // sets the Burst time for current procee SET burstInput ← True // sets busrtInput to true to indicate valid input CATCH InputMismatchException // checks if the user input valid number for Burst time PRINT "Please enter NUMBERS only!" ENDS TRY-CATCH END WHILE // Loop to ensure inputs a valid priority value for each process WHILE priorityInput ← False DO TRY PRINT "Priority:" // Ask the user to input priority value SET Priority[i] ← user input in Priority // sets the priority value for current process SET priorityInput ← True // sets priorityInput to true to indicate valid input CATCH InputMismatchException OUTPUT Please enter a WHOLE NUMBER only!" END TRY CATCH END WHILE END FOR // Creating a copy of priority array to be used for sorting SET P1 ← ARRAY of integer of size job FOR i FROM 0 TO job-1 DO SET P1[i] ← Priority[i] END FOR // Sorting the priority array in ascending order FOR i FROM 0 TO job-1 DO FOR j FROM 0 TO job-2 DO IF Priority[j] > Priority[j+1] THEN SET temp ← Priority[j] SET Priority[j] ← Priority[j+1] SET Priority[j+1] ← temp END IF END FOR END FOR // Initializing variables for calculating waiting and turnaround times SET wait ← 0 SET turnTable ← 0 SET waitingTime ← ARRAY of double of size job SET turnaround ← ARRAY of double of size job SET totalWait ← 0.0 SET totalTurn ← 0.0 SET k ← 0 SET l ← 0 PRINT "Process", "Priority No.", "Burst Time", "Waiting Time", "Turnaround Time" FOR i ← 0 to job-1 DO IF Priority[i] = P1[j] THEN CONTINUE END IF FOR j ← 0 to job-1 DO IF Priority ← P1[j] THEN SET turnTable ← turnTable + Burst[j] PRINT (j+1), P1[j], Burst[j], wait, turnTable SET waitingTime[k] ← wait SET totalWait ← totalWait + wait SET turnround[k] ← waitingTime[k] + Burst[j] END IF END FOR END FOR // Printing the headers for the output table PRINT "AVERAGE WAITING TIME" + totalWait/job + " AVERAGE TURNAROUND TIME: " + totalTurn/job PRINT "Would you like to restart the program? Press [Y] to restart or ANY KEY to terminate:" // Ask the user if they want to restart the program SET restart ← user input // set the value value for restart to what the user input IF restart ← 'Y' // check if the user input letter Y CALL main method // call the main method ELSE // otherwise terminate the program PRINT "Program terminated. Thanks for using the program!" END IF