Professional Documents
Culture Documents
Bully.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
switch (value) {
case 1:
NewCo(ReadyPro);
break;
case 2:
CrashPro(ReadyPro, CrashedPro);
break;
case 3:
RevokePro(ReadyPro, CrashedPro);
break;
case 4:
sc.close();
System.exit(0);
break;
default:
System.out.println("Invalid input. Please enter a valid option.");
break;
}
}
}
public static void NewCo(ArrayList<Integer> ReadyPro) {
System.out.println("The New Co-ordinator is " + Collections.max(ReadyPro));
}
public static void CrashPro(ArrayList<Integer> ReadyPro, ArrayList<Integer> CrashedPro) {
System.out.println("Ready Processes :- " + ReadyPro);
System.out.print("Enter No. of Process to Crash:- ");
int NoCrashPro = sc.nextInt();
System.out.println(NoCrashPro);
ReadyPro.remove(Integer.valueOf(NoCrashPro));
CrashedPro.add(NoCrashPro);
NewCo(ReadyPro);
}
public static void RevokePro(ArrayList<Integer> ReadyPro, ArrayList<Integer> CrashedPro) {
System.out.println("Crashed Processes :- " + CrashedPro);
System.out.print("Enter No. of Process to Revoke :- ");
int NoRevokePro = sc.nextInt();
CrashedPro.remove(Integer.valueOf(NoRevokePro));
ReadyPro.add(NoRevokePro);
NewCo(ReadyPro);
}
}
Output: