Hallo liebe Leute,
ich habe ein kleines Java-Programmierungsproblem. In dem unten stehendem Quellcode müsste die monatliche zahlung bei jedem Output stehen. Nun ist meine Frage.
Wie kann ich die monatliche Zahlung in jedem der 3 Ausgaben einfügen?
Vielen Dank für schnelle Antworten
grüsse
//Mortgage Program /
//This program will calculate and display the mortgage /
//monthly payments for three different loans given the /
//amount, the term and the interest rate of the mortgage. /
//Hardcoded amounts are provided by the instructor. / /
//Version 1 /
//Modification 1 /
//This program has been modified to display 3 mortgage loans,/
//7 year at 5.35%, 15 year at 5.5%, and 30 year at 5.75%, /
//using an array for the different loans. In addition, this /
//program will display the mortgage payment amount for each /
//loan. /
//Version 1.1 /
//////////////////////////////////////////////////////////////
//To set digits after decimal point//
import java.text.NumberFormat;
class MortgageArray {
public static void main(String args[])throws InterruptedException
{
double principal = 200000; //Hardcoded amounts//
double []percent = new double [3];
percent[0] = 5.35/100;
percent[1] = 5.5/100;
percent[2] = 5.75/100;
short []nyears = new short[3];
nyears[0] = 7 ;
nyears[1] = 15;
nyears[2] = 30;
//Used to set two digits after decimal point//
NumberFormat fmt = NumberFormat.getInstance();
fmt.setMaximumFractionDigits(2);
fmt.setMinimumFractionDigits(2);
//Displays Results
System.out.println("\nPrincipal = $" + fmt.format(principal) + "\nInterest = "
+ percent[0] + "%"
+ "\nYears = " + nyears[0]);
System.out.println("Monthly Payments = $ " +fmt.format(pmt));
System.out.println("\nPrincipal = $" + fmt.format(principal) + "\nInterest = "
+ percent[1] + "%"
+ "\nYears = " + nyears[1]);
System.out.println("Monthly Payments = $"+fmt.format(pmt));
System.out.println("\nPrincipal = $" + fmt.format(principal) + "\nInterest = "
+ percent[2] + "%"
+ "\nYears = " + nyears[2]);
System.out.println("Monthly Payments = $"+fmt.format(pmt));
//Formula calculations to figure monthly payments//
//Principal= 200000*(5.75/(1-(1+5.75)^-360))//
//Reference Chou, H.(2000)US Mortgage formula//
double intmo = percent / 12;
int npmts = nyears * 12;
double pmt = principal * (intmo / (1 - Math.pow(1 + intmo, -npmts)));
}
}