Text Share Online

Implement two classes that fulfill the Bank interface.

 

Given an interface named Bank with the following functions:

  • void assignLoans(int[] loans);
  • void averageLoan();
  • void maxLoan();
  • void minLoan();

Create 2 classes, PersonalLoanDept and BusinessLoanDept, implementing the Bank interface.

 

1. The class PersonalLoanDept should include an integer-type array termed loanAmounts and these methods:

  • PersonalLoanDept(int clients): An empty array loanAmounts of clients length is initialized in this class, where clients is the count of loan recipients. The initial loan amount assigned is zero.
  • void assignLoans(int[] loans): The loans array is linked to loanAmounts. If the lengths of the two arrays differ, as many values as possible are assigned, and then stop allocating more and print “Loans for clients processed”.
  • void averageLoan(): This displays the loan average in the pattern “Average loan amount for clients is {averageLoan}“. The average computation should consider any zero value present in loanAmounts and should be rounded to 2 decimal places.
  • void maxLoan(): This displays “Maximum loan amount amongst clients is {maximumLoan}” reflecting the largest loan.
  • void minLoan(): This displays “Minimum loan amount amongst clients is {minimumLoan}” reflecting the smallest loan given.

2. The BusinessLoanDept class needs an int[] as a variable called loanAmounts and should have these methods:

  • BusinessLoanDept(int businesses): This initializes an empty array loanAmounts of length businesses which signifies the number of business recipients.
  • void assignLoans(int[] loans): This assigns loans array to loanAmounts. The system discontinues further allocation if the lengths of arrays do not match post the assignment of possible values and prints “Loans for businesses processed”.
  • void averageLoan(): This prints “Average loan amount for businesses is {averageLoan}“. Any remaining zero values in loanAmounts are included in the average calculation.
  • void maxLoan(): This prints “Maximum loan amongst businesses is {maximumLoan}” reflecting the highest loan.
  • void minLoan(): This prints “Minimum loan amongst businesses is {minimumLoan}” reflecting the lowest loan value.

 

Ensure the usage of inheritance and encapsulation to prevent redundant code. Implementation of the PersonalLoanDept and BusinessLoanDept classes is checked using the interface Bank provided in the locked code stub.

 

 

Share This: