Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java problem

  1. Sep 13, 2005 #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: Sep 13, 2005
  2. jcsd
  3. Sep 13, 2005 #2
    Errors would be nice.

     
  4. Sep 13, 2005 #3
    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.
     
  5. Sep 14, 2005 #4
    :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")
     
  6. Sep 14, 2005 #5
    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Java problem
  1. Java help (Replies: 15)

  2. Java q (Replies: 3)

  3. Java problem. (Replies: 4)

Loading...