From 755352b7c6f69419ae27f799d9b2aa259194bd0a Mon Sep 17 00:00:00 2001 From: aaronkyx Date: Thu, 27 Feb 2020 12:23:17 +0800 Subject: [PATCH] finished --- .../StarterCode_Java/Banker.java | 316 ------------------ 1 file changed, 316 deletions(-) delete mode 100644 BankersAlgorithmLab/StarterCode_Java/Banker.java diff --git a/BankersAlgorithmLab/StarterCode_Java/Banker.java b/BankersAlgorithmLab/StarterCode_Java/Banker.java deleted file mode 100644 index 4876931..0000000 --- a/BankersAlgorithmLab/StarterCode_Java/Banker.java +++ /dev/null @@ -1,316 +0,0 @@ -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.lang.reflect.Array; -import java.util.Arrays; - -public class Banker { - private int numberOfCustomers; // the number of customers - private int numberOfResources; // the number of resources - - private int[] available; // the available amount of each resource - private int[][] maximum; // the maximum demand of each customer - private int[][] allocation; // the amount currently allocated - private int[][] need; // the remaining needs of each customer - - /** - * Constructor for the Banker class. - * @param resources An array of the available count for each resource. - * @param numberOfCustomers The number of customers. - */ - public Banker (int[] resources, int numberOfCustomers) { - // TODO: set the number of resources - this.numberOfResources=resources.length; - // TODO: set the number of customers - this.numberOfCustomers=numberOfCustomers; - // TODO: set the value of bank resources to available - this.available=resources; - // TODO: set the array size for maximum, allocation, and need - maximum =new int[numberOfCustomers][numberOfResources]; - allocation =new int[numberOfCustomers][numberOfResources]; - need = new int[numberOfCustomers][numberOfResources]; - } - - /** - * Sets the maximum number of demand of each resource for a customer. - * @param customerIndex The customer's index (0-indexed). - * @param maximumDemand An array of the maximum demanded count for each resource. - */ - public void setMaximumDemand(int customerIndex, int[] maximumDemand) { - // TODO: add customer, update maximum and need - for (int i =0; ineed[customerIndex][i]) { - // System.out.println("More than allowed"); - return false; - } - - // TODO: check if request larger than available - if (request[i]>available[i]) { - // System.out.println("More than available"); - return false; - } - }; - - // TODO: check if the state is safe or not - if (!checkSafe(customerIndex, request)){ - // System.out.println("Deadlock preempted"); - return false; - } - - // TODO: if it is safe, allocate the resources to customer customerNumber - for (int i=0;i 0) { - runFile(args[0]); - } - } - -} \ No newline at end of file