keifer
02-17-2006, 10:47 PM
I am new to java and this College class is kicking my butt. Here is the question.
Modify the mortgage program to display 3 mortgage loans: 7 year at 5.35%, 15 year at 5.5 %, and 30 year at 5.75%. Use an array for the different loans. Display the mortgage payment amount for each loan. Then, list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen. Do not use a graphical user interface. Insert comments in the program to document the program.
They want it in a 3 dimensional array. Here is my last assignemnt with a 2 dimensional arrray. Could someone help me with the logic on this one. My brain hurts.
/* Name:
Class: POS406
Date:
File: Mortgage4.java
Purpose: Calculate and display morgage data in a array.
*/
//Imported Functions from java
import java.text.DecimalFormat;
import java.math.*;
public class Mortgage4
{
public static void main(String[] args)
{
// Define variables and arrays
int[] term = {7,15,30};
double[] rate = {5.35/100,5.5/100,5.75/100};
double[] balance = {200000,200000,200000};
double[] payment = new double[3];
int i;
// loop to advance each cell
for (i=0;i<3;i++)
{
// payment calculations
payment[i] = ((rate[i]/12)*balance[i])/(1-Math.pow((1+rate[i]/12),-term[i]*12));
DecimalFormat money = new DecimalFormat ("$###,###.00");
DecimalFormat percent = new DecimalFormat ("###.0#");
// Output
System.out.print("A " + money.format(balance[i]) + " mortgage ");
System.out.print("at " + percent.format(rate[i]*100) + "% ");
System.out.print("length " + term[i] + " yr term ");
System.out.println("Payment will be " + money.format(payment[i]) + "!\n");
}
}
}
Modify the mortgage program to display 3 mortgage loans: 7 year at 5.35%, 15 year at 5.5 %, and 30 year at 5.75%. Use an array for the different loans. Display the mortgage payment amount for each loan. Then, list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen. Do not use a graphical user interface. Insert comments in the program to document the program.
They want it in a 3 dimensional array. Here is my last assignemnt with a 2 dimensional arrray. Could someone help me with the logic on this one. My brain hurts.
/* Name:
Class: POS406
Date:
File: Mortgage4.java
Purpose: Calculate and display morgage data in a array.
*/
//Imported Functions from java
import java.text.DecimalFormat;
import java.math.*;
public class Mortgage4
{
public static void main(String[] args)
{
// Define variables and arrays
int[] term = {7,15,30};
double[] rate = {5.35/100,5.5/100,5.75/100};
double[] balance = {200000,200000,200000};
double[] payment = new double[3];
int i;
// loop to advance each cell
for (i=0;i<3;i++)
{
// payment calculations
payment[i] = ((rate[i]/12)*balance[i])/(1-Math.pow((1+rate[i]/12),-term[i]*12));
DecimalFormat money = new DecimalFormat ("$###,###.00");
DecimalFormat percent = new DecimalFormat ("###.0#");
// Output
System.out.print("A " + money.format(balance[i]) + " mortgage ");
System.out.print("at " + percent.format(rate[i]*100) + "% ");
System.out.print("length " + term[i] + " yr term ");
System.out.println("Payment will be " + money.format(payment[i]) + "!\n");
}
}
}