Java Programming: Please Modify the next source code according to the next requirements:
Source:
package bankersdet;
import java.util.Scanner; public class BankersDet{ private int need[][],allocate[][],max[][],avail[][],np,nr;
private void input(){ Scanner sc=new Scanner(System.in); System.out.print("Enter no. of processes and resources : "); np=sc.nextInt();/o. of process nr=sc.nextInt();/o. of resources need=new int[np][nr];//initializing arrays max=new int[np][nr]; allocate=new int[np][nr]; avail=new int[1][nr]; System.out.println("Enter allocation matrix -->"); for(int i=0;i"); for(int i=0;i"); for(int j=0;j return need; }
private boolean check(int i){ //checking if all resources for ith process can be allocated for(int j=0;j return true; } public void isSafe(){ input(); calc_need(); boolean done[]=new boolean[np]; int j=0;
while(j Please implement a program using Java, to simulate the Bankers algorithm for Deadlock detection. The program should detect whether there is any potential deadlock in the given situation of resource availability, allocation and request. A user-friendly graphical interface using independent windows should enable the user to input the required data. 2. Once the fields are filled with the correct data and the "Create Matrix" button 1. When the program is executed, is clicked, a new window should display the following matrix (Size of Matrix a new window should prompt the depends on the number of processes:number of resources). The user should be user to enter the number of able to fill the matrix with the necesary input for the operation (use textfields) processes and the number of resources for the desired operation. (Only numbers should be accepted). R1 R2 R3 R4. R1 R2 R3 R4 R1 R2 R3 R4 P1 P1 P1 P2 P2 R1 R2 R3 R4 Welcome P3 P3 P3 of processes 3 Available Need Max Allocation of resources Detect Deadlock Create Matrix 3. Once the matrix are correctly filled (only numbers) and the "Detect Deadlock" button is clicked, the program should detect if there is deadlock in the data inputted by the user 4. A new window should inform the user if there is possibility of deadlock or no, and Deadlock detected in... if there is, it would be nice to show where. A little button in this window should allow the user to perform a new deadlock test. (First window should prompt again and program restarts New deadlock test For Reference on Bankers algorithm and how it works please use the following video: Deadlock Banker's Algorithm Deadlock not possible. Mifta Sintaha New deadlock test Subscribe 15,504 Please implement a program using Java, to simulate the Bankers algorithm for Deadlock detection. The program should detect whether there is any potential deadlock in the given situation of resource availability, allocation and request. A user-friendly graphical interface using independent windows should enable the user to input the required data. 2. Once the fields are filled with the correct data and the "Create Matrix" button 1. When the program is executed, is clicked, a new window should display the following matrix (Size of Matrix a new window should prompt the depends on the number of processes:number of resources). The user should be user to enter the number of able to fill the matrix with the necesary input for the operation (use textfields) processes and the number of resources for the desired operation. (Only numbers should be accepted). R1 R2 R3 R4. R1 R2 R3 R4 R1 R2 R3 R4 P1 P1 P1 P2 P2 R1 R2 R3 R4 Welcome P3 P3 P3 of processes 3 Available Need Max Allocation of resources Detect Deadlock Create Matrix 3. Once the matrix are correctly filled (only numbers) and the "Detect Deadlock" button is clicked, the program should detect if there is deadlock in the data inputted by the user 4. A new window should inform the user if there is possibility of deadlock or no, and Deadlock detected in... if there is, it would be nice to show where. A little button in this window should allow the user to perform a new deadlock test. (First window should prompt again and program restarts New deadlock test For Reference on Bankers algorithm and how it works please use the following video: Deadlock Banker's Algorithm Deadlock not possible. Mifta Sintaha New deadlock test Subscribe 15,504