# Please help

Printable View

• 05-04-2011, 04:21 PM
starplayerrob
Please help
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 :)
• 05-04-2011, 04:37 PM
ojn
Quote:

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?

Quote:

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.
Quote:

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.
• 05-04-2011, 04:58 PM
starplayerrob
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
• 05-04-2011, 05:11 PM
yellowledbet
x*x;

or

Math.pow(x, 2);
Math (Java 2 Platform SE v1.4.2)
• 05-04-2011, 05:19 PM
starplayerrob
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)
• 05-04-2011, 05:24 PM
yellowledbet
I am not %100 sure about this but I would think that you need a loop

Something like this
Code:

``` double investment = ENTERINVESTMENTHERE; for(int i = 0; i < 12; i++){       investment = investment *(1 + interestRate); }```
this is just a guess
• 05-04-2011, 05:28 PM
starplayerrob
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..
• 05-04-2011, 05:31 PM
ojn
Is year declared anywhere? And do you know there's a difference between year++ and ++year?
• 05-04-2011, 05:37 PM
starplayerrob
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 :)
• 05-04-2011, 05:39 PM
starplayerrob
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);
}
}
}
• 05-04-2011, 07:50 PM
ojn
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:
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?
• 05-04-2011, 09:39 PM
starplayerrob
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