Java Multidimensional Arrays

Reply

Join Date: Nov 2004
Posts: 3
Reputation: ljraven is an unknown quantity at this point 
Solved Threads: 0
ljraven ljraven is offline Offline
Newbie Poster

Java Multidimensional Arrays

 
0
  #1
Nov 5th, 2004
Hello:

I am a student and am attempting to write a multidimensional array for a Mortgage Calculator program. We have to display three different mortgage's that display 3 different interest rates and term years that show the calculated mortgage payment amount. I have the following code and am receiving many errors and I can't progress unless I can figure out what I am doing wrong, so if anyone can give me some guidance I would appreciate it. Thanks. ljraven

import java.util.*;

public class MortgageArray
{
public static void main(String[] args) throws Exception
{

double[][] mortgage = new mortgage [3][4];

{ {200000, 7, 5.35, 0.0},
{200000, 15, 5.5, 0.0},
{200000, 30, 5.75, 0.0} };

System.out.println("Mortgage amount is \t" + $);
System.out.println("Term of mortgage is \t" + "years");
System.out.println("Interest rate is \t" "%");
System.out.println("Monthly mortgage payment \t" $);



}
}
}




C:\Java\MortgageArray.java:10: not a statement
{ {200000, 7, 5.35, 0.0},
^
C:\Java\MortgageArray.java:10: ';' expected
{ {200000, 7, 5.35, 0.0},
^
C:\Java\MortgageArray.java:10: illegal start of expression
{ {200000, 7, 5.35, 0.0},
^
C:\Java\MortgageArray.java:12: ';' expected
{200000, 30, 5.75, 0.0} };
^
C:\Java\MortgageArray.java:14: ')' expected
System.out.println("Mortgage amount is \t" + 0,0$ );
^
C:\Java\MortgageArray.java:15: ')' expected
System.out.println("Term of mortgage is \t" + 0,1 "years");
^
C:\Java\MortgageArray.java:16: ')' expected
System.out.println("Interest rate is \t" 0,3 "%");
^
C:\Java\MortgageArray.java:17: ')' expected
System.out.println("Monthly mortgage payment \t" 0,4$ );
^
C:\Java\MortgageArray.java:23: 'class' or 'interface' expected
}
^
C:\Java\MortgageArray.java:27: 'class' or 'interface' expected
^
10 errors

Tool completed with exit code 1
:cry:
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Java Multidimensional Arrays

 
0
  #2
Nov 6th, 2004
You wanted something like this perhaps?
  1. public class MortgageArray {
  2. public static void main (String[] args) throws Exception {
  3. double[][] mortgage = {
  4. {200000, 7, 5.35, 0.0},
  5. {200000, 15, 5.5, 0.0},
  6. {200000, 30, 5.75, 0.0}
  7. };
  8.  
  9. System.out.println ("Mortgage amount is \t" + mortgage[0][0]);
  10. System.out.println ("Term of mortgage is \t" + mortgage[0][1] + "years");
  11. System.out.println ("Interest rate is \t" + mortgage[0][2] + "%");
  12. System.out.println ("Monthly mortgage payment \t" + mortgage[0][3] + "$");
  13. }
  14. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 3
Reputation: ljraven is an unknown quantity at this point 
Solved Threads: 0
ljraven ljraven is offline Offline
Newbie Poster

Calculations in Java Multidimensional Arrays

 
0
  #3
Nov 7th, 2004
Originally Posted by Narue
You wanted something like this perhaps?
  1. public class MortgageArray {
  2. public static void main (String[] args) throws Exception {
  3. double[][] mortgage = {
  4. {200000, 7, 5.35, 0.0},
  5. {200000, 15, 5.5, 0.0},
  6. {200000, 30, 5.75, 0.0}
  7. };
  8.  
  9. System.out.println ("Mortgage amount is \t" + mortgage[0][0]);
  10. System.out.println ("Term of mortgage is \t" + mortgage[0][1] + "years");
  11. System.out.println ("Interest rate is \t" + mortgage[0][2] + "%");
  12. System.out.println ("Monthly mortgage payment \t" + mortgage[0][3] + "$");
  13. }
  14. }

Yes, I tried that, but obviously had something wrong. Thanks. So, if I put in another two set of print statements and tell it to give the output for the other two sets of variables, that will work great. I still have the problem with calculating the mortgage payment.

With using normal variabales, the code for calculating the mortgage payment is something like

Payment = (principal * interest) / (1 - Math.pow(1 + interest, -Term of loan)

When I do the calculations, I get an output that is close, but when I use the same calculation with the array method I receive an error that says you can't use *-+/ with arrays. I can't believe that is true. So any suggestions on how to make the calculations work.

I would think that it would be similar except that I think that you insert them in a different location than with just the declared variable method.

Suggestions would be greatly appreciated. I really appreciate the help.

ljraven
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Java Multidimensional Arrays

 
0
  #4
Nov 7th, 2004
>I receive an error that says you can't use *-+/ with arrays
I would wager that you aren't properly subscripting the array. Just remember that array is an array of arrays of type double, array[x] is an array of double, and array[x][y] is a double.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 3
Reputation: ljraven is an unknown quantity at this point 
Solved Threads: 0
ljraven ljraven is offline Offline
Newbie Poster

Re: Java Multidimensional Arrays

 
0
  #5
Nov 9th, 2004
public class MortgageArray4A
{
public static void main(String[] args) throws Exception
{

double[][] mortgage =

{{200000, 7, 5.35, 0.0},
{200000, 15, 5.5, 0.0},
{200000, 30, 5.75, 0.0} };

//This is what the output should calculate and display

for (int i = 0; i < 3 ; i++)
{
System.out.println ("Mortgage amount is \t" + mortgage[i][0]);
System.out.println ("Term of mortgage is \t" + mortgage[i][1] + years");
System.out.println ("Interest rate is \t" + mortgage[i][2] + "%");
System.out.println ("Monthly mortgage payment \t$" + (mortgage[i][0]
+ ((mortgage[i][0] * mortgage[i][2]/100))/(mortgage[i][1]*12)) ");
}
}

//My instructor helped me with the last print statement, I knew I was
//missing the necessary instructions. So, now I just have to get it to
//continue the loop so it display's the rest of the payments until the
//balance reaches zero. I appreciate the help that you have provided. :eek:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC