I am having problems with a mortgage calculator that I created and already handed in yesterday as an assignment in my Java class at UoP. The program runs fine enough to hand in. The problem is that the calculation comes out in months instead of years and I want the calculation to come out in years. I had to change my wording in my output to months and add the month to year conversion above the loop. I want the program to calculate to years so I can remover the month to year conversion. The payment amount is correct though. The code is listed below, can someone tell me what I need to change,thanks.
/**
Programming 420 Week 4 Mortgage Calculator by Amanda Smith
*/
//The java.io package provides for system input and output through data streams
import java.io.*;
//A subclass of the NumberFormat used to format numbers in Java programs
import java.text.DecimalFormat;
public class AmandaMortgageRate
{
//The main function for the mortgage calculator
public static void main(String[] args) throws IOException
{
//Declaring and constructing variables
int [] iTerm = {84, 180, 360};
double [] dInterest = {5.35, 5.5, 5.75};
double dPayment, dRate, dAmount = 200000, dMonthlyInterest,dMonthlyPrincipal, dMonthlyBalance;
DecimalFormat twoDigits = new DecimalFormat("$#,000.00");
//output for month to years
System.out.println();
System.out.println("Welcome to Amanda's Mortgage Calculator");
System.out.println();
System.out.println("An 84-month loan equals a 7-year loan.");
System.out.println("A 180-month loan equals a 15-year loan.");
System.out.println("A 360-month loan equals a 30-year loan.");
System.out.println();
//Loop for the varying Mortgage Rates and Payments
int p;
for (p = 0; p <= 2; p ++)
{
//Calculation for the monthly mortgage payment
//Calculations Retrieved from http://www.1728.com/loanform.htm on 8/15/08
dRate = dInterest[p] / 1200;
dPayment = (dAmount * dRate) / (1 - Math.pow(1 / (1 + dRate), iTerm[p]));
dMonthlyInterest = (dAmount / 12) * (dInterest[p] / 100);
dMonthlyPrincipal = (dPayment - dMonthlyInterest);
dMonthlyBalance = (dAmount - dMonthlyPrincipal);
// Output for the loan information and the monthly payment
System.out.println();
System.out.println("Your Monthly Payment for a " + iTerm[p] +" month loan of $200,000 at " + dInterest[p] + "% is:" + twoDigits.format (dPayment));
System.out.println();
}
}
//function for the calculation of the interest into the loan payment
public double MonthlyInterest()
{
//Declaring Variables for interest on the loan
double dMonthlyInterest = 0.0;
double dAmount = 0.0;
double dInterest = 0.0;
//Calculation for monthly interest
dMonthlyInterest = (dAmount / 12) * (dInterest / 100);
return dMonthlyInterest;
}
//function for the calculation of the interest into the loan payment
public double monthlyInterest()
{
//Declaring Variables for interest on the loan
double dMonthlyInterest = 0.0;
double dAmount = 0.0;
double dInterest = 0.0;
//Calculation for monthly interest
dMonthlyInterest = (dAmount / 12) * (dInterest / 100);
return dMonthlyInterest;
}
//function of the calculation of the monthly principal for the loan payment
public static double monthlyPrincipal()
{
//Declaring Variables for monthly principal
double dMonthlyPrincipal = 0.0;
double dPayment = 0.0;
double dMonthlyInterest = 0.0;
//Calculations for monthly principal
dMonthlyPrincipal = (dPayment - dMonthlyInterest);
return dMonthlyPrincipal;
}
//function for the calculation of the monthy loan balance
public static double monthlyBalance()
{
//Declaring Variables for monthly loan balance
double dMonthlyBalance = 0.0;
double dAmount = 0.0;
double dMonthlyPrincipal = 0.0;
//Calculations for monthly loan balance
dMonthlyBalance = (dAmount - dMonthlyPrincipal);
return dMonthlyBalance;
}
}
Java Mortgage Calculator Problemchanging code to calculator years instead of months
Page 1 of 1
2 Replies - 6348 Views - Last Post: 07 May 2008 - 09:47 AM
Topic Sponsor:
Replies To: Java Mortgage Calculator Problem
#2
Re: Java Mortgage Calculator Problem
Posted 07 May 2008 - 09:07 AM
Please post you code like this: 
Silly question can't you just replace
by
Silly question can't you just replace
// Output for the loan information and the monthly payment
System.out.println();
System.out.println("Your Monthly Payment for a " + iTerm[p] +" month loan of $200,000 at " + dInterest[p]+ "% is:" + twoDigits.format (dPayment));
System.out.println();
by
int nbYear = iTerm[p] / 12;
System.out.println();
System.out.println("Your Monthly Payment for a " + nbYear +" years loan of $200,000 at " + dInterest[p]+ "% is:" + twoDigits.format (dPayment));
System.out.println();
#3
Re: Java Mortgage Calculator Problem
Posted 07 May 2008 - 09:47 AM
Thanks so much. I am a total newbie at Java and the classes at UoP are only 5 weeks long, and this was only my third assignment, it took me 3 days just to figure out how to write the program, but I am learning, thanks so much for helping me as I wanted this issue fixed before I add the loop for the amortization on the 3 loan amounts that is due next monday, thanks again.
pbl, on 7 May, 2008 - 09:07 AM, said:
Please post you code like this: 
Silly question can't you just replace
by
Silly question can't you just replace
// Output for the loan information and the monthly payment
System.out.println();
System.out.println("Your Monthly Payment for a " + iTerm[p] +" month loan of $200,000 at " + dInterest[p]+ "% is:" + twoDigits.format (dPayment));
System.out.println();
by
int nbYear = iTerm[p] / 12;
System.out.println();
System.out.println("Your Monthly Payment for a " + nbYear +" years loan of $200,000 at " + dInterest[p]+ "% is:" + twoDigits.format (dPayment));
System.out.println();
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|