1. Member
Join Date
Apr 2011
Posts
37
Rep Power
0

how do i make JOptionPane in textpad display a table with the headings "year" and "investmentAmount"

i also have the formula: futureInvestmentValue = investment *(1 + interestRate)*(year*12);
in order to calculate the investment amount (yearly) after it accumulates monthly interest.. but it wont calculate right so if anyone can help me please do.. i need answers asap thank you all :)

2. Senior Member
Join Date
Sep 2008
Location
Stockholm, Sweden
Posts
119
Rep Power
0
Originally Posted by starplayerrob
how do i make JOptionPane in textpad display a table with the headings "year" and "investmentAmount"
textpad? Do you mean the text editor? If so, why does the choice of editor matter? Why do you think a JOptionPane is good for this?

i also have the formula: futureInvestmentValue = investment *(1 + interestRate)*(year*12);
in order to calculate the investment amount (yearly) after it accumulates monthly interest.. but it wont calculate right
Math question rather than a Java question so I'll leave it to a match wiz to look at.
i need answers asap thank you all :)
No one gives a damn how fast you need it and just mentioning you need it "asap" is very rude and will deter people from wanting to help you.

3. Member
Join Date
Apr 2011
Posts
37
Rep Power
0
was not meaning to be rude at all and u saying no one gives a damn is rude. JOptionPane is what i have to use and TextPad5 is the program im using to create the program..

also do u know how to write x squared in java

4. Senior Member
Join Date
Feb 2011
Location
Georgia, USA
Posts
122
Rep Power
0
x*x;

or

Math.pow(x, 2);
Math (Java 2 Platform SE v1.4.2)

5. Member
Join Date
Apr 2011
Posts
37
Rep Power
0
if i was to write this formula futureInvestmentValue = investment *(1 + interestRate)*(year*12)
how do i make it where (year*12) is like this..
futureInvestmentValue = investment *(1 + interestRate)^(year*12)

6. Senior Member
Join Date
Feb 2011
Location
Georgia, USA
Posts
122
Rep Power
0

Something like this
Java Code:
```double investment = ENTERINVESTMENTHERE;

for(int i = 0; i < 12; i++){
investment = investment *(1 + interestRate);
}```
this is just a guess

7. Member
Join Date
Apr 2011
Posts
37
Rep Power
0
yes that seems right but the interestrate is monthly so i need it to also multiply by 12months right?

for(int i = 0; i < 12; i++){
investment = investment *(1 + interestRate);

this is what mine looks like
for(year = 1; year <= MAX_YEAR; ++year)
{
futureInvestmentValue = investment *(1 + interestRate)*(year*12);

but it wont compile..

8. Senior Member
Join Date
Sep 2008
Location
Stockholm, Sweden
Posts
119
Rep Power
0
Is year declared anywhere? And do you know there's a difference between year++ and ++year?

9. Member
Join Date
Apr 2011
Posts
37
Rep Power
0
yes year is decalred as an int and year++ increments up right? could u help clear that part up for me that would be great :)

10. Member
Join Date
Apr 2011
Posts
37
Rep Power
0
this will probably help u help me :)
[-i have to write a test program that prompts the user (using JOptionPane) to enter the investment amount (e.g., 1000) and the interest rate (e.g., 9%) and prints a table that displays future value for the years from 1 to 30 like this...
Years Future Value
1 \$1093.89
2 \$1196.41

29 \$13467.25
30 \$14730.57

what i have so far is this:

import java.util.Scanner;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Investment
{
public static void main(String[] args)
{
double investment;
double interestRate;
double futureInvestmentValue;
int year;
final int MAX_YEAR = 30;
String entry;

DecimalFormat myDecimal = new DecimalFormat("\$#,###.##");

entry = JOptionPane.showInputDialog(null, "How much are you investing?");
investment = Double.parseDouble(entry);

entry = JOptionPane.showInputDialog(null, "What is the interest rate?");
interestRate = Double.parseDouble(entry);

Scanner keyboard = new Scanner(System.in);

for(year = 1; year <= MAX_YEAR; ++year)
{
futureInvestmentValue = investment *(1 + interestRate)*(year*12);
System.out.println("After year " + year + " investment is \$" + investment);
}
}
}

11. Senior Member
Join Date
Sep 2008
Location
Stockholm, Sweden
Posts
119
Rep Power
0
Ok, now things make a lot more sense. :) Just make sure you put your code within PHP tags in the future, it makes it much easier to read. Just mark your code and click the PHP icon above the editbox.

It will give this output:
PHP Code:
```import java.util.Scanner;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Investment
{
public static void main(String[] args)
{
double investment;
double interestRate;
double futureInvestmentValue;
int year;
final int MAX_YEAR = 30;
String entry;

DecimalFormat myDecimal = new DecimalFormat("\$#,###.##");

entry = JOptionPane.showInputDialog(null, "How much are you investing?");
investment = Double.parseDouble(entry);

entry = JOptionPane.showInputDialog(null, "What is the interest rate?");
interestRate = Double.parseDouble(entry);

Scanner keyboard = new Scanner(System.in);

for(year = 1; year <= MAX_YEAR; ++year)
{
futureInvestmentValue = investment * (1 + interestRate) * (year*12);
System.out.println("After year " + year + " investment is \$" + investment);
}
}
}```
Much easier to read, wouldn't you agree?

Now, what's wrong with your code? Does it compile? If not, what error messages do you get, and for what lines? Is there a logic error? If so, what's the output now (if any) and does it differ from what you expected?

12. Member
Join Date
Apr 2011
Posts
37
Rep Power
0
it odes not dispay the output in one table it displays as individual messages and the investment amount is the same so there is something wrong with my math formula maybe but im not seeing it. where i used system.out.println on the last line i need to use joptionpane. and yes thank you much easier to read

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•