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

Any help would be greatly appreciated. I\'ll link the problem first: Write a pro

ID: 3640429 • Letter: A

Question

Any help would be greatly appreciated. I'll link the problem first:

Write a program to find all unsafe banks. Your program reads the input as
follows. It first reads two integers n and limit, where n indicates the number of
banks and limit the minimum total assets for keeping a bank safe. It then reads
n lines that describe the information for n banks with id from 0 to n-1. The first
number in the line is the bank’s balance, the second number indicates the
number of banks that borrowed money from the bank, and the rest are pairs of
two numbers. Each pair describes a borrower. The first number in the pair is the
borrower’s id and the second is the amount borrowed. For example, the input
for the five banks in Figure 1 is as follows (note that the limit is 201):
>5 201
>25 2 1 100.5 4 320.5
>125 2 2 40 3 85
>175 2 0 125 3 75
>75 1 0 125
>181 1 2 125
The total assets of bank 3 are (75 + 125 = balance + loan), which is under
201. So bank 3 is unsafe. After bank 3 becomes unsafe, the total assets of bank
1 will fall below (125 + 40). So, bank 1 is also unsafe. The output of the program
should be
>Unsafe banks are 3 1
(Hint: Use a two-dimensional array borrowers to represent loans.
borrowers[i][j] indicates the loan that bank i loans to bank j. Once bank j
becomes unsafe, borrowers[i][j] should be set to 0.)







This is what I have so far, but not sure if it's right:

import java.util.Scanner;

public class Pa4 {
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 = input.nextDouble();
int borrowedBanks = input.nextInt();


double[][] borrowers = new double[n][n];
double totalAssets = balance + ;


for (int i = 0; i < n; i++){
for(int j = 0; j < n; j++)
borrowers[i][j] = input.nextDouble();





At the moment I am having difficulty understanding how to create the input correctly. I think i'm missing something. Like I said, any help would be great, I have been working on this for four hours :(

Explanation / Answer

Don't Forget to rate Life Saver!!

Just run the code line by line.. I made it simpler than my previous post. Basically StringTokenizer will help you read input values from console and ask me where you have trouble understanding. This should be more than get you started...just display banks fail.

Program Output :

Enter > Banks Total [space] Banks Limit   

> 5 201

Enter    > BALANCE [space] TOTAL_BANKS_BORROWED [space] BANK_NAME [space] LOAN_AMOUNT....]

Bank [0] > 25 2 1 100.5 4 320.5

Bank [1] > 125 2 2 40 3 85

Bank [2] > 175 2 0 125 3 75

Bank [3] > 75 1 0 125

Bank [4] > 181 1 2 125


Bank [0] Total ASSETS : 446.0M Banks Loaned [1 4 0 0 0 ]

Bank [1] Total ASSETS : 250.0M Banks Loaned [2 3 0 0 0 ]

Bank [2] Total ASSETS : 375.0M Banks Loaned [0 3 0 0 0 ]

Bank [3] Total ASSETS : 200.0M Banks Loaned [0 0 0 0 0 ]

Bank [4] Total ASSETS : 306.0M Banks Loaned [2 0 0 0 0 ]


public class BankLoan {

    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        int totalBanks = 0;
        double bankLimit = 0;
        double[] bankAssets;
        int[][] borrowers;
        // Splits the string input.
        java.util.StringTokenizer token = null;

        String input = null;

        System.out.println("Enter    > Banks Total [space] Banks Limit");
        System.out.print("         > ");
        input = sc.nextLine();

        // Split input into tokens by space;
        token = new java.util.StringTokenizer(input, " ");

        totalBanks = Integer.parseInt(token.nextToken());
        bankLimit = Double.parseDouble(token.nextToken());

        bankAssets = new double[totalBanks];
        borrowers = new int[totalBanks][totalBanks];
        
        System.out.println();
        System.out.println("Enter    > BALANCE [space] TOTAL_BANKS_BORROWED [space] BANK_NAME [space] LOAN_AMOUNT....]");

        for (int bank = 0; bank < totalBanks; bank++) {
            System.out.print("Bank [" + bank + "] > ");
            input = sc.nextLine();

            token = new java.util.StringTokenizer(input, " ");

            bankAssets[bank] = bankAssets[bank]+ Integer.parseInt(token.nextToken());
            int totalBorrowed = Integer.parseInt(token.nextToken());
            for (int borrowed = 0; borrowed < totalBorrowed; borrowed++) {
                // stores borrowed bank i loaned to bank j
                borrowers[bank][borrowed] = Integer.parseInt(token.nextToken());
                // balance + loan = totalAssets
                bankAssets[bank] = bankAssets[bank] + Double.parseDouble(token.nextToken());
            }
            //System.out.println("Bank ["+bank+"] Assets : " +bankAssets[bank]);
        }
        
        System.out.println();
        for(int i=0; i<bankAssets.length; i++) {
            System.out.print("Bank ["+i+"] Total ASSETS : "+bankAssets[i]+ "M Banks Loaned [");
            for(int j=0; j<borrowers.length;j++) {                
                System.out.print(borrowers[i][j]+ " ");
            }
            System.out.println("]");
        }


    }
}
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