Java problem

  • Thread starter bomba923
  • Start date
  • #1
bomba923
760
0
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:

Answers and Replies

  • #2
ComputerGeek
383
0
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
 
  • #3
DrMark
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.
 
  • #4
bomba923
760
0
: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")
 
  • #5
gnome
1,037
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
 

Suggested for: Java problem

Replies
14
Views
158
  • Last Post
Replies
6
Views
413
  • Last Post
Replies
9
Views
507
Replies
9
Views
891
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
10
Views
1K
  • Last Post
Replies
10
Views
2K
  • Last Post
Replies
11
Views
617
Replies
8
Views
508
Replies
9
Views
634
Top