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

Regions Bank received a complaint from a customer stating that their loan paymen

ID: 3787209 • Letter: R

Question

Regions Bank received a complaint from a customer stating that their loan payments for a house loan of $150,000 were not accurately processed. The car loan was a 0% interest loan over a 360 month period and the client does not believe the bank has the correct balance for her loan account. The bank states that they have a loan balance of $136500 but the customer has copies of 10 payments made to the bank. A bank teller made a copy of the payments and entered them into a file.

Create a MortgageLoan class

To verify the banks total, read the file and write a program using a MorgageLoan class that extends the BankAccount class  (BankAccount class is provided below).

The MortgageLoan class has the following features: an overload constructor that initializes the mortgage loan balance. (Hint: Uses super to set the balance.)

Create a MortgageLoanClient class that

Create MortgageLoan object

Read the file one payment at a time (Include exception handling code).

Use the payment read from the file to pass the information to the method to calculate the outstanding balance (Use the withdrawal method).

Printout the payment number, payment amount and outstanding balance.

Continue to process for each payment until the end of the file.

Create a text file with the following numbers which represent the monthly payments made by the customer.

3150

4051

3105

3704

3053

3015

4050

4784

4102

3015

4095

4076

3201

3105

4006

3209

3260

3560

3105

3250

// Java Class BankAccount.java
import java.text.DecimalFormat;
public class BankAccount{

public final DecimalFormat MONEY = new DecimalFormat("$#, ##0.00");

protected double balance;//Default constructorpublic BankAccount(){

balance=0.0;

}

//overloaded constructor

public BankAccount(double startBalance){

deposit(startBalance);

}

//accessor for balance

public double getBalance(){

return balance;

}

//deposit amount to account

public void deposit(double amount){

if(amount >= 0.0){

balance += amount;

}

else{

System.err.println(" Deposit amount must be positive.");

}

}

//withdraw amount from account

public void withdraw(double amount){

if(amount >= 0 && amount <= balance){

balance = balance - amount;

}

else{

System.err.println(" Withdraw amount must be positive and cannot be greater than balance.");

}
}//return balance formatted as money

public String toString(){

return ("Your current outstanding balance is now " + MONEY.format(balance));

}

}

3150

4051

3105

3704

3053

3015

4050

4784

4102

3015

4095

4076

3201

3105

4006

3209

3260

3560

3105

3250

Explanation / Answer

import java.text.DecimalFormat;

public class BankAccount {
   public final DecimalFormat MONEY = new DecimalFormat("$#, ##0.00");
   protected double balance;// Default constructorpublic

   BankAccount() {
       balance = 0.0;
   }

   // overloaded constructor
   public BankAccount(double startBalance) {
       deposit(startBalance);
   }

   // accessor for balance
   public double getBalance() {
       return balance;
   }

   // deposit amount to account
   public void deposit(double amount) {
       if (amount >= 0.0) {
           balance += amount;
       } else {
           System.err.println(" Deposit amount must be positive.");
       }
   }

   // withdraw amount from account
   public void withdraw(double amount) {
       if (amount >= 0 && amount <= balance) {
           balance = balance - amount;
       } else {
           System.err
                   .println(" Withdraw amount must be positive and cannot be greater than balance.");
       }
   }// return balance formatted as money

   public String toString() {
       return ("Your current outstanding balance is now " + MONEY
               .format(balance));
   }

}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class MortgageLoan extends BankAccount {

   private int mortgageLoanBalance;

   public int getMortgageLoanBalance() {
       return mortgageLoanBalance;
   }

   public void setMortgageLoanBalance(int mortgageLoanBalance) {
       this.mortgageLoanBalance = mortgageLoanBalance;
   }

   public MortgageLoan() {
       this.mortgageLoanBalance = mortgageLoanBalance;
   }

   public MortgageLoan(int mortgageLoanBalance) {

       this.mortgageLoanBalance = mortgageLoanBalance;
   }

   public MortgageLoan(double startBalance, int mortgageLoanBalance) {
       super(startBalance);
       this.mortgageLoanBalance = mortgageLoanBalance;
   }

   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       System.out.println("enter the starting mortgage loan balance");
       int loanAmount = scanner.nextInt();
       MortgageLoan loan = new MortgageLoan();
       loan.setMortgageLoanBalance(loanAmount);
       int loanBalance=loan.calculatePaymentAmount();
       System.out.println("the loan balance is "+loanBalance);
       scanner.close();
   }

   private int calculatePaymentAmount() {
String line=null;
int count=1;
       try {

           BufferedReader reader = new BufferedReader(new FileReader(new File(
                   "D:\loanpayments.txt")));
           while(( line=reader.readLine())!=null)
           {
               int loanpayment=Integer.parseInt(line);
               mortgageLoanBalance=mortgageLoanBalance-loanpayment;
               System.out.println("the mortgage loan balance is after the payment is "+mortgageLoanBalance+" "+count++);
              
           }
       } catch (FileNotFoundException f) {
           System.out.println("please attach correct file");
           calculatePaymentAmount();
       } catch (IOException e) {
           System.out
                   .println("error reading the file please read another time");

       }

       return mortgageLoanBalance;
   }
  

}


public class SubmittedWrongFilException extends Exception {
  
   public String msg;

   public SubmittedWrongFilException(String msg) {
       super();
       this.msg = msg;
   }
  

}

enter the starting mortgage loan balance
150000
the mortgage loan balance is after the payment is 146850 0
the mortgage loan balance is after the payment is 142799 1
the mortgage loan balance is after the payment is 139694 2
the mortgage loan balance is after the payment is 135990 3
the mortgage loan balance is after the payment is 132937 4
the mortgage loan balance is after the payment is 129922 5
the mortgage loan balance is after the payment is 125872 6
the mortgage loan balance is after the payment is 121088 7
the mortgage loan balance is after the payment is 116986 8
the mortgage loan balance is after the payment is 113971 9
the mortgage loan balance is after the payment is 109876 10
the mortgage loan balance is after the payment is 105800 11
the mortgage loan balance is after the payment is 102599 12
the mortgage loan balance is after the payment is 99494 13
the mortgage loan balance is after the payment is 95488 14
the mortgage loan balance is after the payment is 92279 15
the mortgage loan balance is after the payment is 89019 16
the mortgage loan balance is after the payment is 85459 17
the mortgage loan balance is after the payment is 82354 18
the mortgage loan balance is after the payment is 79104 19
the loan balance is 79104