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

CAIS-0339 Complete a Banker\'s Algorithm code that handles a single request for

ID: 3705735 • Letter: C

Question

CAIS-0339 Complete a Banker's Algorithm code that handles a single request for resources from a process based on the current resource allocation state as represented below private static finat int -5 1number of processes prs.ate statu fanal ant " . ?? // 'saber @" resource types prawate int[][] Allocation " ( ?". 1. .), // A1tocation for process 2. .)ocaton for process locats 21, 117ecaion or process e, e, 2/ Allocatson for process prlvate int11 Need-1743at resource need Tor process . . 2),stonal ressurce need for process 4,3,1al resue need for process The template for the code is provided, and you need to complete two methods within the code: i.e. resourceRequestAlgorithm and safetyAlgorithm. resourceRequestAlgorithm must follow the logic as shown by the comments within, and likewise for safety Algorithm. The slides on which these algorithms are based can be found in slide 33 and 32 for Chapter 07 respectively. The following shows a snapshot of interaction where process 0 requests for (0,2, 0) instances of resource types 0, 1, and 2 respectively. Enter process Ld (8-411 Enter requested quantity fer resource :0 Enter requested quantity for resource 2: 2 Enter requested quantity for resource 2: 124 Safe The program handles only one request, and exits Special Note Do not declare/define any new variables, methods or classes within the template. Do note add any new file to your submission. IF ANY OF THESE REQUIREMENTS IS BROKEN YOU WILL GET NO CREDIT FOR THIS HOMEWORK bmiss You must submit the completed Java template file.

Explanation / Answer

import com.x5.template.Chunk;
import java.io,*;
public boolean SaftyAlgorithm()
{
int []work=new int[M];
boolean finish=new boolean[M];
int i,j,k;
int pflag=0,flag=0;
for(i=0;i<n;i++)
finish[i]=0;
for(i=0;i<m;i++)
work[0][i]=availabe[0][i];
{
for(k=0;k<n;k++){
for(i=0;i<n;i++)
{
if(finish[i] == 0){
flag=0;
for(j=0;j<m;j++){
if(need[i][j]>work[0][j])
flag=1;
}
if(flag == 0 && F[i] == 0){
for(j=0;j<m;j++)
work[0][j]+=available[i][j];
finish[i]=1;
pflag++;
available[x++]=i;
}
}
}
if(pflag == n)
return true;
}
return false;
}

}
public void resourseAllocationAlgoritm(int pid ,int[] request)
{
for(int i=0;i<m;i++)
{
if(rquest[0][i]>need[pid][i])
{
System.out.println("error Occoured");
return ;
}
for(i=0;i<m;i++)
if(requesi[i] > available[0][i]){
System.out.println(" Resources unavailable.");
return ;
}
for(int i=0;i<m;i++)
{
available[0][i]=request[i];
available[pid][i]+=request[i];
need[pid][i]-=request[i];
}
return ;
}
//please notify me if anything is not correct
//or need to be change

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote