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

import java.util.Scanner; public class Test { public static void main(String[] a

ID: 3640554 • Letter: I

Question

import java.util.Scanner;

public class Test {

public static void main(String[] args){

Scanner input= new Scanner(System.in);

       System.out.print(" Enter Number Of Banks and minimum assets for keeping a bank safe : ");

       int n = input.nextInt();

       int limit = input.nextInt();

       System.out.print(" Now enter the bank's balance, the number of banks that borrowed money from the bank," +

                     (" and the borrower's i.d along with the amount borrowed : "));

       double[] balance = new double[n];

       double[][] borrowers = new double [n][n];

       boolean isSafe[]= new boolean[n];

       boolean unsafeBankDiscovered = true;

       double assets[]=new double[n];

       for (int i = 0; i < n; i++)

       {

           balance[i] = input.nextDouble();

           int m = input.nextInt(); //number of banks borrowing from bank i

           for(int k = 0; k < m; k++)

           {

           int id = input.nextInt();

              double loan = input.nextDouble();

              borrowers[i][id]= loan;

           }

       // set array to all true

    isSafe[i] = true ;

       }   

    // Unsafe banks are:

    while(unsafeBankDiscovered)

    {

       for(int i =0; i < n; i++)

         {

         for(int j=0; j < n;)

         {

         isSafe[i]=false;

         assets[i] = balance[i]; //set assets to balance

           if(borrowers[i][j] > 0)

           {

                    assets[i] += borrowers[i][j];

            }

             if(assets[i] < limit) // check to see if current bank meets limit

            {

                isSafe[i] = false; // set bank to not safe if limit not met

             borrowers[i][j] = 0; //set banks loans to 0 if unsafe.

            }

         }

         }

    }

       for(int i=0; i<n;i++) {

             if(!isSafe[i])

             System.out.print(" Unsafe banks are " +i);

             }

}     

}


Explanation / Answer

import java.util.Scanner; public class Test { public static void main(String[] args){ Scanner input= new Scanner(System.in); System.out.print(" Enter Number Of Banks and minimum assets for keeping a bank safe : "); int n = input.nextInt(); int limit = input.nextInt(); System.out.print(" Now enter the bank's balance, the number of banks that borrowed money from the bank," + (" and the borrower's i.d along with the amount borrowed : ")); double[] balance = new double[n]; double[][][] borrowers = new double [n][n][n]; boolean isSafe[]= new boolean[n]; for (int i = 0; i