Java code for three mortgage loans

Java code for three mortgage loans - stumped - please help

Page 1 of 1

2 Replies - 2194 Views - Last Post: 25 March 2009 - 12:18 AM Rate Topic: -----

#1 jdfrost  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-March 09

Java code for three mortgage loans

Posted 23 March 2009 - 08:42 PM

I am taking a course in Java programming through my college and am writing a program for a mortgage pymnt calculator for 3 loans and need to get each loan to a balance of $0.00 - any help would be greatly appreciated. Following is the code:
import java.text.*;
public class Main
{

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// This area declares the variables (loan amount, term and rate). Arrays used in this section.
float loanAmount = 200000;
int term[] = {7, 15, 30};
double rate[] = {5.35, 5.5, 5.75};

DecimalFormat dfm = new DecimalFormat(",##0.00");

// The for loop of this program.
for (int i=0; i<3; i++)

{
// This function displays the monthly payment.
double monthlyPayment = ((loanAmount * ((rate[i] / 100) / 12)) /
(1 - (Math.pow(1 / (1 + ((rate[i] / 100) / 12)), term[i] * 12))));

// This function displays the set up for the amortized mortgage payments.
double monthlyPrinciple = 0, monthlyInterest = 0, currentBalance = 0;
currentBalance = loanAmount;

//The calculation for the code.
monthlyInterest = currentBalance * rate[i]/(12*100);
monthlyPrinciple = monthlyPayment - monthlyInterest;
currentBalance = currentBalance - monthlyPrinciple;

//These are the details of the monthly payments, interest, principle & balance.
System.out.println("Monthly Payment = $" + dfm.format(monthlyPayment) );
System.out.println("Monthly Interest = $" + dfm.format(monthlyInterest) );
System.out.println("Monthly Principle = $" + dfm.format(monthlyPrinciple) );
System.out.println("Current Balance = " + dfm.format(currentBalance) );
System.out.println("\n");
}
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: Java code for three mortgage loans

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Java code for three mortgage loans

Posted 24 March 2009 - 05:58 AM

post your code between code tags please, and also include a description of the problems you are facing and if you are getting any errors
Was This Post Helpful? 0
  • +
  • -

#3 jdfrost  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-March 09

Re: Java code for three mortgage loans

Posted 25 March 2009 - 12:18 AM

View Postmostyfriedman, on 24 Mar, 2009 - 04:58 AM, said:

post your code between code tags please, and also include a description of the problems you are facing and if you are getting any errors


I was able to get the program working but now am stumped again - the final process of the assignment / program is as follows:
Extend your Java Project with the following items:
Incorporate functionality that accepts user input for:
- The principal
- The interest rate
- The number of years
The program must display the monthly payment and then loops by requesting (using the switch function) the following options:
- C or c: Calculate another payment
- X or x: Exit program


Any pointers on performing this task would be greatly appreciated - not asking for someone to do the work but mainly asking for some assistance on this matter.

Thanks -
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1