| | |
Java Multidimensional Arrays
![]() |
•
•
Join Date: Nov 2004
Posts: 3
Reputation:
Solved Threads: 0
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:
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:
You wanted something like this perhaps?
Java Syntax (Toggle Plain Text)
public class MortgageArray { 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} }; System.out.println ("Mortgage amount is \t" + mortgage[0][0]); System.out.println ("Term of mortgage is \t" + mortgage[0][1] + "years"); System.out.println ("Interest rate is \t" + mortgage[0][2] + "%"); System.out.println ("Monthly mortgage payment \t" + mortgage[0][3] + "$"); } }
I'm here to prove you wrong.
•
•
Join Date: Nov 2004
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Narue
You wanted something like this perhaps?
Java Syntax (Toggle Plain Text)
public class MortgageArray { 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} }; System.out.println ("Mortgage amount is \t" + mortgage[0][0]); System.out.println ("Term of mortgage is \t" + mortgage[0][1] + "years"); System.out.println ("Interest rate is \t" + mortgage[0][2] + "%"); System.out.println ("Monthly mortgage payment \t" + mortgage[0][3] + "$"); } }
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
•
•
Join Date: Nov 2004
Posts: 3
Reputation:
Solved Threads: 0
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:
{
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:
![]() |
Similar Threads
- Comparing multidimensional arrays (Java)
- Java newbie needs help with arrays (Java)
- Passing Multidimensional Arrays To Functions (C++)
- Need help sorting a file in java (Java)
- Initializing Multidimensional Arrays plz help! (C++)
Other Threads in the Java Forum
- Previous Thread: how willl i be able to save a specific record into my database file in ms access
- Next Thread: need help with program feture to cellular
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card chat class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting scanner se server service set sms socket software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






