Troubleshooting Final Balance Calculator Program

AI Thread Summary
The discussion focuses on troubleshooting a Java program designed to calculate final balances based on user inputs. Key issues identified include the incorrect assignment of variables, where the initial balance (b0) was not defined before use, and ty was mistakenly assigned as the initial balance instead of the number of years. Additionally, there were syntax errors, such as using "PrintIn" instead of "println," which caused compilation issues. Users also noted potential problems with the Java compiler not being found, suggesting that the Java bin directory might not be properly set in the system's environment variables. The conversation emphasizes the importance of correctly defining variables and ensuring the programming environment is correctly configured for successful compilation.
bomba923
Messages
759
Reaction score
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:
Computer science news on Phys.org
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
 
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")
 
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
 
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...

Similar threads

Back
Top