Click to See Complete Forum and Search --> : Java Question


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");

}

}
}

bwkaz
02-18-2006, 10:11 AM
I don't see any two-dimensional arrays in there...

IIRC, in Java you declare a two-dimensional array of doubles as:

double[][] xxx = {
{1.0, 1.0, 1.0},
{1.0, 1.0, 1.0}
}; (This will create an array whose first dimension ranges from 0 to 1, and whose second dimension ranges from 0 to 2. I think, anyway -- it's been a while since I've done Java.)

The corresponding 3-D version would be:

int[][][] xxx = {
{
{0,1},
{0,1}
},
{
{0,1},
{0,1}
}
}; (This is a 2x2x2 array.) Now, I'm not going to solve your entire question here, because I don't want to do your homework for you. But it sounds like this might give you a start, at least?

keifer
02-18-2006, 11:31 AM
Yea, was looking for more of a push in the right direction. Thanks, any help people can give is great.