Hey guys! help me out, i'm really out of ideas, how can i save the datas i inputed to have a rotation of value , like the computation in the withdraw, when i 1st use the withdraw or deposit, it computes, yes but when the 2nd time i use it, it still on 10000 value.
heres my codes
(sorry not my native language)

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bank;
import java.util.Scanner;

/**
 *
 * @author rerei
 */
public class Bank {
public static Scanner input;
public static int anotherTransact;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    input = new Scanner (System.in);
    System.out.println("\t\t!WELCOME!");
    menu();
    }

    public static void menu(){
        char choice;
        double Balance = 10000;
        double Deposit, Withdraw, newBalance;
        System.out.print("====================================================\n"
                + "  [A] Withdraw\n  [B] Deposit\n  [C] Check Balance\n  [D] Exit\n"
                + "Choose Transaction : ");
        choice = input.next().charAt(0);
        System.out.print("====================================================\n");
            if(choice !='A' && choice !='a' && choice !='B' && choice !='b' && choice !='C' && choice !='c' && choice !='D' && choice !='d'){
                System.out.println("Invalid Choice!\nTry Again!");
                menu();
            }

            switch (choice){

                case 'A': case 'a': //withdraw

                    System.out.print("Withdraw Amount : ");
                        Withdraw = input.nextDouble();
                        newBalance = Balance - Withdraw;
                    System.out.println("====================================================");

                        if (Balance <=5000){
                            System.out.println("You Need To Maintain 5000PHP On Your Account!");
                        }if (Balance >=50000){
                            System.out.println("You Reached The 50000PHP Withdrawal Limit!");
                        }if (Balance > 5000 && Balance <50000){
                            System.out.println("You Withdraw : " + Withdraw + "PHP," + "Your New Balance is : " + Balance + "PHP");                        
                        }   anotherTransact();
                            break;

                case 'B': case 'b'://Deposit

                    System.out.print("Deposit Amount : ");
                        Deposit = input.nextDouble();
                        newBalance = Balance + Deposit;
                    System.out.println("====================================================");
                    System.out.println("You Deposited : " + Deposit +"PHP," + "Your New Balance is : " + Balance +"PHP");
                            anotherTransact();    
                            break;

                case 'C': case 'c': //Check Balance

                    System.out.println("Current Balance : " + newBalance + "PHP");
                            anotherTransact();
                            break;

                case 'D': case 'd'://Exit
                    System.out.println("Thank You And See You Again!");
                    break;
            }           
    }
    public static void anotherTransact(){
        System.out.println("Do You Want Another Transaction? : [1] Yes [2] No\n");
        anotherTransact = input.nextInt();

        if (anotherTransact == 1){
            System.out.println("Are You Sure? : [1] Yes [2] No");
                anotherTransact = input.nextInt();
                if(anotherTransact == 1){
                    menu();
                }else{
                    anotherTransact();
                }
        }
        else if (anotherTransact == 2){
            System.out.println("Are You Sure? : [1] Yes [2] No");
                anotherTransact = input.nextInt();
                if(anotherTransact == 1){
                    System.out.println("Thank You And See You Again1");
                }else{
                    anotherTransact();
                }
        }
        else{
            System.out.println("Invalid Choice!\nTry Again!");
            System.out.println("==============================================");
            anotherTransact();
        }   
    }
}

help me out , thanks in advance

Recommended Answers

All 4 Replies

You create the new balance in newBalance, but then you ignore that.
Either just update Balance directly, or copy newBalance to Balance at the end of the transaction.

sorry that was a typo, i fixed that already thanks! :)

I'm not sure if each time can be a withdraw of 1 unit, but in that case, calling anotherTransct() from menu(), then menu() from anotherTransact() and repeating this same process enough times, there could be a stack overflow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.