I have one, reoccurring issue that arises each time I run this incomplete program I am working on; I have spent much time attempting to locate the bug. I am convinced it arises from a simple error.
Problem: User has made a "deposit" but when the User makes a "withdrawal", the "balance" is an incorrect and negative number always.
Any help in or push in the right direction would be greatly appreciated. Thank-you in advance.
import java.io.*;
final class readString {
public static void main (String[] args) {
// Intro
System.out.print("Welcome to World Bank. Please make a selection from the following and selct the Enter key:\n 1)Checking\n 2)Savings\n 3)Loans\n Choice:");
// Open Input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String choice1 = "1";
String choice2 = "2";
String deposit1 = "1";
String deposit2;
String withdrawal1 ="1";
String withdrawal2 = null;
String response1 = "Checking";
String response2 = "Savings";
String response3 = "Loans";
try {
choice1 = br.readLine();
if (choice1.equals("1"))
{
System.out.println("You chose " + response1);
System.out.println("Please choose 1 for deposit or 2 for withdrawal:");
deposit1 = br.readLine();
System.out.println("Please make your deposit:");
deposit2 = br.readLine();
System.out.println("You deposited " + deposit2 + ".");
System.out.println("Would you like to make a withdrawal? Here you may make a withdrawal and see your balance. Enter 1 to go to Withdrawal area.");
deposit2 = br.readLine();
System.out.println("You chose " + withdrawal1);
System.out.println("Please enter the amount you would like to withdrawal: ");
withdrawal2 = br.readLine();
System.out.println("You have withdrawn: $" + withdrawal2 + ".00.");
String convert1 = deposit2;
int newdeposit1 = Integer.parseInt(convert1);
String convert2 = withdrawal2;
int newWithdrawal = Integer.parseInt(convert2);
{
int Balance1 = newdeposit1 - newWithdrawal;
System.out.println("Your balance is: $" + Balance1 + ".00.");
}
}
if (choice1.equals("2"))
{
System.out.println("You chose " + response2);
}
if (choice1.equals("3"))
{
System.out.println("You chose " + response3);
}
}
catch (IOException ioe) {
System.out.println("Error deteceted.");
System.exit(1);
}