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
 
This week, I saw a documentary done by the French called Les sacrifiés de l'IA, which was presented by a Canadian show Enquête. If you understand French I recommend it. Very eye-opening. I found a similar documentary in English called The Human Cost of AI: Data workers in the Global South. There is also an interview with Milagros Miceli (appearing in both documentaries) on Youtube: I also found a powerpoint presentation by the economist Uma Rani (appearing in the French documentary), AI...

Similar threads

Back
Top