Question

In: Computer Science

Modify the mortgage program to display 3 mortgage loans: 7 years at 5.35%, 15 year at...

Modify the mortgage program to display 3 mortgage loans: 7 years at 5.35%, 15 year at 5.5%, and 30 years at 5.75%. Use an array for the different loans. Display the mortgage payment amount for each loan. Do no use graphical user interface. Insert comments in the program to document the program.

***********Please look at my code so far. Still having trouble with arrays. Want to know if I'm going the right path********

import java.util.Scanner;
public class MortPay2
{
public static void main(String args[])
{
//declaration section
double principal, monthlyPayment;
int choice;
Scanner input = new Scanner(System.in);

   int term [] = {84, 180, 360}; //term in months
   double rate [] = {.0044, .0046, .0048};//rate in decimal format

  
   //display section
   System.out.println("Please select from 3 loan options.");
   System.out.println("1. Loan 1: 7 year term at 5.35% interest.");
   System.out.println("2. Loan 2: 15 year term at 5.5% interest.");
   System.out.println("3. Loan 3: 30 year term at 5.75% interest.");
   choice = input.nextInt();

   if (choice ==1)
   {
       System.out.println("You have chosen Loan 1.");
       System.out.println("Please enter the loan amount: $");
       principal = input.nextDouble();

       for ( int i = 0; i<3; i++)
       {
           monthlyPayment = principal * rate[0] / (1.0 - Math.pow (rate[0] + 1), -term[0]));
           System.out.println("Total monthly mortgae payment is $%.2f%n", monthlyPayment);
}
   }
  
  
}
}
  
      
  

Solutions

Expert Solution

JAVA PROGRAM

/////////////////////////////MortPay2.java////////////////////////////

import java.util.Scanner;
public class MortPay2{
   public static void main(String args[]){
   //declaration section
   double principal, monthlyPayment;
   int choice;
   Scanner input = new Scanner(System.in);
      
   int term [] = {84, 180, 360}; //term in months
   double rate [] = {.0044, .0046, .0048};//rate in decimal format; stored as (yearlyRate/12)
  
  
   //display section
   System.out.println("Please select from 3 loan options.");
   System.out.println("1. Loan 1: 7 year term at 5.35% interest.");
   System.out.println("2. Loan 2: 15 year term at 5.5% interest.");
   System.out.println("3. Loan 3: 30 year term at 5.75% interest.");
   System.out.println("4. Display all Loans");//added this option to show all options at a time
     
   choice = input.nextInt();
     
   int index = 0,termInMonth;
   double mortgageRate;
     
   if (choice ==1){
   System.out.println("You have chosen Loan 1.");
   index =0; //as we need to consider 0th index element from both term and rate array
   }else if(choice ==2){
       System.out.println("You have chosen Loan 2.");
   index =1; //as we need to consider 1st index element from both term and rate array
   }else if(choice ==3){
       System.out.println("You have chosen Loan 3.");
   index =2; //as we need to consider 2nd index element from both term and rate array
   }else {
       System.out.println("You have chosen to display all loans.");
       index = -1; //this is set in this way to show all loans
   }
     
System.out.println("Please enter the loan amount: $");
principal = input.nextDouble();

   if(index==-1){//if index = -1 show all loans
   for(int i = 0; i < 3 ; i++){//loop from i = 0 to 2
       //calculate monthly payment for ith index loan
           monthlyPayment = principal * rate[i]/ (1.0 - Math.pow (rate[i] + 1, -term[i]));
           //print the monthly payment
           System.out.printf("\nLoan %d : Total monthly mortgae payment is $%.2f%n", i+1,monthlyPayment);
   }
   }else{//otherwise display for specific loan
       mortgageRate = rate[index];//get rate for the index
       termInMonth = term[index];//get term for the index
       //calculate monthly payment
       monthlyPayment = principal * mortgageRate/ (1.0 - Math.pow (mortgageRate+ 1, -termInMonth));
       //print it
       System.out.printf("\nLoan %d : Total monthly mortgae payment is $%.2f%n", index+1,monthlyPayment);
   }
  
   input.close();//close scanner
   System.out.println("\nThank you!");
   }
}

=====================================

OUTPUT

====================================

Run1

Please select from 3 loan options.
1. Loan 1: 7 year term at 5.35% interest.
2. Loan 2: 15 year term at 5.5% interest.
3. Loan 3: 30 year term at 5.75% interest.
4. Display all Loans
1
You have chosen Loan 1.
Please enter the loan amount: $
15000

Loan 1 : Total monthly mortgae payment is $213.99

Thank you!

Run2

Please select from 3 loan options.
1. Loan 1: 7 year term at 5.35% interest.
2. Loan 2: 15 year term at 5.5% interest.
3. Loan 3: 30 year term at 5.75% interest.
4. Display all Loans
2
You have chosen Loan 2.
Please enter the loan amount: $
16000

Loan 2 : Total monthly mortgae payment is $130.90

Thank you!

Run3

Please select from 3 loan options.
1. Loan 1: 7 year term at 5.35% interest.
2. Loan 2: 15 year term at 5.5% interest.
3. Loan 3: 30 year term at 5.75% interest.
4. Display all Loans
3
You have chosen Loan 3.
Please enter the loan amount: $
17000

Loan 3 : Total monthly mortgae payment is $99.32

Thank you!

Run4

Please select from 3 loan options.
1. Loan 1: 7 year term at 5.35% interest.
2. Loan 2: 15 year term at 5.5% interest.
3. Loan 3: 30 year term at 5.75% interest.
4. Display all Loans
4
You have chosen to display all loans.
Please enter the loan amount: $
20000

Loan 1 : Total monthly mortgae payment is $285.32

Loan 2 : Total monthly mortgae payment is $163.63

Loan 3 : Total monthly mortgae payment is $116.84

Thank you!


Related Solutions

Currently, 30-year and 15-year mortgage loans can be taken with 3% and 2.5% annual interest rates,...
Currently, 30-year and 15-year mortgage loans can be taken with 3% and 2.5% annual interest rates, respectively. If you want to purchase a $300,000 value house with a 5% down payment. What would be your monthly payments for each mortgage loans; 30-year? and 15-year mortgages? Please show me the work?
Need to create Mortgage Calculator Program In C++ Modify your mortgage to include two functions. A...
Need to create Mortgage Calculator Program In C++ Modify your mortgage to include two functions. A function to get principal, rate, and term. A function to calculate monthly payment. Test your program by getting the data from the user by using the first function and calculate monthly payment by calling the other function. Add version control and write proper comments with a few blank lines & indentations in order to improve your programming style.
Loan 3: 15-year versus 30-year mortgage Amortize a mortgage for a $225,000 house with a 20%...
Loan 3: 15-year versus 30-year mortgage Amortize a mortgage for a $225,000 house with a 20% down payment for both a 15-year mortgage at 3.625% and a 30-year mortgage at 4.125%. 15-year mortgage monthly payment? What is the total interest cost over the life of the 15-year loan? 30-year mortgage monthly payment? What is the total interest cost over the life of the 30-year loan? Difference in interest costs between a 15-year and a 30-year mortgage?
Modify the Movie List 2D program -Modify the program so it contains four columns: name, year,...
Modify the Movie List 2D program -Modify the program so it contains four columns: name, year, price and rating (G,PG,R…) -Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating def list(movie_list): if len(movie_list) == 0: print("There are no movies in the list.\n") return else: i = 1 for row in movie_list: print(str(i) + ". " + row[0] + " (" + str(row[1]) + ")") i += 1...
A pool of mortgages contains 3%, 15-year loans with the total beginning balance of $100 million....
A pool of mortgages contains 3%, 15-year loans with the total beginning balance of $100 million. The pool backs 116 principal-only (PO) shares and 99 interest-only (IO) shares. Monthly expenses and fees amount to 0.04% of the beginning-of-the-month balance (they are subtracted from the interest portion). In the first month, the total payments from the pool were $713.3 thousand. What was the cash flow per PO share (to the nearest dollar)? Assume no defaults.
Flint Company loans Sarasota Company $1,870,000 at 7% for 3 years on January 1, 2017. Flint...
Flint Company loans Sarasota Company $1,870,000 at 7% for 3 years on January 1, 2017. Flint intends to hold this loan to maturity. The fair value of the loan at the end of each reporting period is as follows. December 31, 2017 $1,924,000. December 31, 2018 1,892,000 December 31, 2019 1,870,000 Prepare the journal entry(ies) at December 31, 2017, and December 31, 2019, for Flint related to these bonds, assuming (a) it does not use the fair value option, and...
You bought a house 8 years ago with a $250,000 mortgage. It was a 15 year loan with
You bought a house 8 years ago with a $250,000 mortgage. It was a 15 year loan with monthly payments which will pay off the loan when you make the last payment. The interest rate was 6%. What are your monthly payment and your current loan balance? How much interest will you pay in the upcoming year?  
you just bought a house and have a $188,000 mortgage. the mortgage is for 15 years...
you just bought a house and have a $188,000 mortgage. the mortgage is for 15 years and has a nominal rate of 4.25%.on the 24th payment what will be the amount going to principal?
Consider a 15 year mortgage with a 3% APR interest rate and a 20% down payment...
Consider a 15 year mortgage with a 3% APR interest rate and a 20% down payment if you can afford a $1500 monthly payment, how expensive a house can you buy? a. $254,250 b. $217,208 c. $271,510 d. $298,402
Marcel Thiessen purchased a home for $203,400 and obtained a 15-year, fixed-rate mortgage at 7% after...
Marcel Thiessen purchased a home for $203,400 and obtained a 15-year, fixed-rate mortgage at 7% after paying a down payment of 10%. Of the first month's mortgage payment, how much is interest and how much is applied to the principal? (Round your answer to the nearest cent.) interest     $ applied to the principal     $
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT