mortgage program to display 3 mortgage loans:
7 year at 5.25%, 15 year at 5.45 %, and 30 year at 5.05%.
Use an array for the different loans (the array will be needed in the next course).
Display the mortgage payment amount for each loan. Do not use a graphical user interface.
7 year at 5.25%, 15 year at 5.45 %, and 30 year at 5.05%.
Use an array for the different loans (the array will be needed in the next course).
Display the mortgage payment amount for each loan. Do not use a graphical user interface.
import java.io.*; // java input output package
import java.text.DecimalFormat;
class MortgageArray
{
public static void main(String[] arguments)
{
//starts the array
double amount = 200000;
int[]term = {7, 15, 30};
double[] rate = {.0525, .0545, .0505};
DecimalFormat twoDigits = new DecimalFormat("$000.00");
System.out.println("With the loan amount of " +twoDigits.format(amount));
for (int i = 0; i < rate.length; i++)
{
System.out.print("for " + term[i] + " years");
System.out.print("\tat a rate of " + rate[i]);
double payment = (amount*(rate[i]/12))/(1-(Math.pow(1/(1+(rate
[i]/12)),(term[i]*12))));
System.out.println("\tThe monthly payment will be " +twoDigits.format(payment));
}
}
}