Java problem (1 Viewer)

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Why won't this work? :frown:
----------------------------------------
import javax.swing.JOptionPane ;

public class FinalBalanceCalculator {

public static void main(String args[]) {

String input;
String name;
double b0;
double rc;
double ty;
double ans;

input = JOptionPane.showInputDialog("What is your name?") ;
name = input ;

input = JOptionPane.showInputDialog("What is your interest rate?") ;
rc = Double.parseDouble(input);

input = JOptionPane.showInputDialog("What is your initial balance?" );
ty = Double.parseDouble(input) ;

ans = Math.pow(1 + rc,ty) * b0 ;

System.out.PrintIn(name + "has an initial balance of $" + b0 + ",") ;
System.out.PrintIn("which is compounded annually at " + rc + "%") ;
System.out.PrintIn("After " + ty + " years, " + name + " will have exactly:") ;
System.out.PrintIn("$" + ans ) ;

}//main
}//FinalBalanceCalculator
 
Last edited:
Errors would be nice.

bomba923 said:
Why won't this work? :frown:
----------------------------------------
import javax.swing.JOptionPane ;

public class FinalBalanceCalculator {

public static void main(String args[]) {

String input;
String name;
double b0;
double rc;
double ty;
double ans;

input = JOptionPane.showInputDialog("What is your name?") ;
name = input ;

input = JOptionPane.showInputDialog("What is your interest rate?") ;
rc = Double.parseDouble(input);

input = JOptionPane.showInputDialog("What is your initial balance?" );
ty = Double.parseDouble(input) ;

ans = Math.pow(1 + rc,ty) * b0 ;

System.out.PrintIn(name + "has an initial balance of $" + b0 + ",") ;
System.out.PrintIn("which is compounded annually at " + rc + "%") ;
System.out.PrintIn("After " + ty + " years, " + name + " will have exactly:") ;
System.out.PrintIn("$" + ans ) ;

}//main
}//FinalBalanceCalculator
 
92
0
I don't program in Java so I could be missing something, but in your input you define ty as the initial balance, in the output you say ty is the number of years and b0 is never defined in the input, but is the initial balance in the output. So me thinks you need b0 for initial balance (not ty) and you need to add a statement to get the number of years (ty) in the input.
 
:smile: Thanx, I fixed it as :
---------------------------------
import javax.swing.JOptionPane ;

public class FinalBalanceCalculator {

public static void main(String args[]) {

String input;
String name;
double b0;
double rc;
double ty;
double ans;

input = JOptionPane.showInputDialog("What is your name?") ;
name = input ;

input = JOptionPane.showInputDialog("What is your initial balance?" );
b0 = Double.parseDouble(input) ;

input = JOptionPane.showInputDialog("What is your interest rate?") ;
rc = Double.parseDouble(input );

input = JOptionPane.showInputDialog("How long will you keep this money?" );
ty = Double.parseDouble(input) ;

ans = Math.pow(1 + rc,ty) * b0 ;

System.out.PrintIn(name + "has an initial balance of $" + b0 + ",") ;
System.out.PrintIn("which is compounded annually at " + rc + "%") ;
System.out.PrintIn("After " + ty + " years, " + name + " will have exactly:") ;
System.out.PrintIn("$" + ans ) ;

}//main
}//FinalBalanceCalculator
-------------------------------------
*It appears on the error sheet that there is a problem with the compiler, javac.exe
and it cannot be found. I download "JDK5.0 Update 4" and programmed with Jgrasp,
but do I need an additional compiler where I download elsewhere?
(a sort of path problem, in regards to a javac.exe missing from a "working directory")
 
1,032
1
System.out.PrintIn should be System.out.println

i.e. the "I" should be an "l"


Also, you have a decimal point problem in your interest rate calculation, but you can figure that out for yourself.
-------------
I don't know anything about Jgrasp (I've never used it), but your compiler problem may be just that your java bin directory is not listed in your path (in your environment variables).
Or maybe there's some problem with your installation of Jgrasp.
Have you tried to compile from the Dos command line? Open a DOS Command Prompt window, chdir to the directory that contains your java source code and enter:

> javac FinalBalanceCalculator.java
 

The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top