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

Top Flight Flying School needs to take out a loan to support their business. The

ID: 3835671 • Letter: T

Question

Top Flight Flying School needs to take out a loan to support their business. They have asked you to write a program to calculate monthly payments for each or 3 mortgage Scenarios and to print the information from each scenario.

To accomplish this task, you will first write the pseudocode lines that will accept the input values from the keyboard for each scenario (shown below as 'Console Inputs'), calculate the monthly payment for each scenario , print out the results for each scenario, then print the scenario with the lowest monthly payment (shown below as 'Console Outputs') . Write the pseudocde on the tab provided "Exam 2 - Write your pseudocode".

Next, you will convert your pseudocode algorithm to a Java program called LoanAnalysis.java that will ask for the console inputs, do the calculation of monthly payment for each scenario, and output the results. Enter your Java program into a new project on Eclipse, run your LoanAnalysis program to test it and make sure you get the same monthly payment amounts for each scenario as shown below. Make sure your console outputs looks like what is shown.

<----Calculated/Expected Output

Variables Formulas Scenario A Scenario B Scenario C la Loan Amount (for example 100000) 125000 125000 100000 <----Inputs air Annual Interest Rate (for example 0.025) 0.02 0.03 0.025 <----Inputs ny Number of Years 15 10 25 <----Inputs PPY Payments per Year (a CONSTANT value of 12) 12 12 12 <----Constant irpp Interest Rate per period = air / ppy 0.00167 0.00250 0.00208 <----Calculated tp Total Payments = ppy * ny 180 120 300 <----Calculated mp Monthly Payment = la*(irpp*(1 + irpp)tp)/((1 + irpp)tp - 1) 804.39 1207.01 448.62 <----Calculated/Expected Output tlap Total Loan Amount Paid (mp * tp) 144789.46 144841.12 134585.02

<----Calculated/Expected Output

Console Inputs: Enter Loan Amount for Scenario A: Enter Annual Interest rate for Scenario A: Enter Number of Years for Scenario A: Enter Loan Amount for Scenario B: Enter Annual Interest rate for Scenario B: Enter Number of Years for Scenario B: Enter Loan Amount for Scenario C: Enter Annual Interest rate for Scenario C: Enter Number of Years for Scenario C: Console Outputs (format output as shown so that the numbers for each scenario line up in columns): b=blank Scenario A bbbbbMonthly Payment:bbb$####.##bbbbbTotal Loan Payment:bbb$######.## Scenario B bbbbbMonthly Payment:bbb$####.##bbbbbTotal Loan Payment:bbb$######.## Scenario C bbbbbMonthly Payment:bbb$####.##bbbbbTotal Loan Payment:bbb$######.##

Explanation / Answer

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class LoanAnalysis {
public static final int PPY = 12;

public static void main(String[] args) {
  Scanner s = new Scanner(System.in);
  List<String> mortGateScenarios = new ArrayList<String>();
  mortGateScenarios.add("A");
  mortGateScenarios.add("B");
  mortGateScenarios.add("C");
  for (String scenarioType : mortGateScenarios) {
   System.out.println("Enter Loan Amount for Scenario" + scenarioType
     + ":");
   double loanAmt = s.nextDouble();
   System.out.println("Enter Annual Interest rate for Scenario"
     + scenarioType + ":");
   double interestRate = s.nextDouble();
   System.out.println("Enter Number of Years for Scenario"
     + scenarioType + ":");
   int noOfYears = s.nextInt();
   calcualteMonthlyPaymentAmt(scenarioType, loanAmt, interestRate,
     noOfYears);
  }

}

static void calcualteMonthlyPaymentAmt(String scenario, double loanAmt,
   double intRate, int numofYears) {
  double intRatePerPeriod = intRate / PPY;
  double totalPayments = numofYears * PPY;
  double monthlyPayments = loanAmt * intRatePerPeriod
    * (Math.pow(1 + intRatePerPeriod, totalPayments))
    / (Math.pow(1 + intRatePerPeriod, totalPayments) - 1);
  double totalLoanAmtPaid = monthlyPayments * totalPayments;
  System.out
    .printf("%s Monthly Payment:   $%.2f Total Loan Payment:   $%.2f ",
      scenario, monthlyPayments, totalLoanAmtPaid);

}

}