# Java code for three mortgage loans

Page 1 of 1

## 2 Replies - 2915 Views - Last Post: 25 March 2009 - 12:18 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=94940&amp;s=3bfa3ca6c2d6a133c0057b0868c38fee&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jdfrost

Reputation: 0
• 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

• The Algorithmi

Reputation: 729
• 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

### #3 jdfrost

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

## Re: Java code for three mortgage loans

Posted 25 March 2009 - 12:18 AM

mostyfriedman, 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 -

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }