Untitled
unknown
plain_text
2 years ago
1.9 kB
1
Indexable
Never
import java.lang.reflect.Array; import java.util.*; class Obj { int time; int index; Obj(int t, int i) { time = t; index = i; } } class Scheduling implements Runnable { int[] tasks; Scheduling(int processes[]) { tasks = processes; run(); } void FCFS() throws InterruptedException { for (int i = 0; i < tasks.length; i++) { try { System.out.println("Process-" + (i + 1) + " executing"); Thread.sleep(tasks[i]); } catch (InterruptedException e) { e.printStackTrace(); } } } void SJF() { Obj[] temp= new Obj[tasks.length]; for (int i = 0; i < tasks.length; i++) { int x= tasks[i]; temp[i]= new Obj(tasks[i],i); } for (int i = 0; i < tasks.length; i++) { System.out.println(temp[i].index + " :" + temp[i].time); } // Arrays.sort(); for (int i = 0; i < tasks.length; i++) { try { System.out.println("Process-" + (i + 1) + " executing"); Thread.sleep(tasks[i]); } catch (InterruptedException e) { e.printStackTrace(); } } } @Override public void run() { Scanner sc = new Scanner(System.in); int ch = 0; while (ch != -1) { System.out.println("\n1.FCFS\n2.SJF\n3.Priorioty\n4.Round Robin\nENTER: "); ch = sc.nextInt(); if (ch == -1) continue; try { switch (ch) { case 1: { FCFS(); break; } case 2: { SJF(); break; } case 3: { priority(); break; } case 4: { roundRobin(); break; } default: throw new IllegalArgumentException("Unexpected value: " + ch); } } catch (Exception e) { // TODO: handle exception } } sc.close(); } private void roundRobin() { // TODO Auto-generated method stub } private void priority() { // TODO Auto-generated method stub } } public class main { public static void main(String[] args) { int processes[] = { 300, 125, 400, 150, 100 }; Scheduling obj = new Scheduling(processes); } }