-2

"I am trying to make a banking application that updates the balance everytime you enter a deposit or a withdraw. I got the menu and everything else to work nicely but while printing out the final balance, the balance always stays at 5000.00. Where did I go wrong?"

            double balance = 5000.00;

                    switch(menu){

                            case 'd': case 'D':
                                double deposit = depositFunds(balance); 
                                break;

                            case 'w': case 'W':
                                double withdrawl = withdrawFunds(balance);
                                break;

                            case 'b': case 'B':
                                checkBalance(accountNumber, balance);
                                break;

                    }//end of switch     

    }//end of main

     public static double depositFunds(double balance){

        Scanner input = new Scanner(System.in);

        System.out.print("\nEnter the amount of the deposit: ");

        double deposit = input.nextInt();

        double currentBalance = (balance + deposit);

        return currentBalance;

     }//end of depositFunds

     public static double withdrawFunds (double balance){

            Scanner input = new Scanner(System.in);

            double currentBalance;

            System.out.print("\nEnter the amount of the withdrawal: ");

            double withdrawal = input.nextInt();

            currentBalance = (balance - withdrawal);

            return currentBalance;

     }//end of withdrawFunds

     //Display the balance
     public static void checkBalance(int accountNumber, double balance){

            System.out.printf("\nAccount Number: %d has a current balance of: %.2f\n" , accountNumber , balance);

     }//end of checkBalance
Cy Yatez
  • 17
  • 2

1 Answers1

0

Do this instead:

switch(menu){

                        case 'd': case 'D':
                            balance = depositFunds(balance); 
                            break;

                        case 'w': case 'W':
                            balance = withdrawFunds(balance);
                            break;

                        case 'b': case 'B':
                            checkBalance(accountNumber, balance);
                            break;

             }
AlphaQ
  • 656
  • 8
  • 18