Getting Bugs from Banking Application

// Class Bank

public class Bank
{
    private String name;
    private String branch;
    private String accountNumber;
    private String address;
    private String username;
    private String password;
    private int netAmount;
    private int amount;
    final int INITIAL_AMOUNT;

    public Bank(String name, String branch, String address)
    {
        INITIAL_AMOUNT = 5000;
        netAmount = INITIAL_AMOUNT;
        this.name = name;
        this.branch = branch;
        this.address = address;
    }
    public boolean createUser(String username, String password)
    {
        if(username.equals("") || password.equals(""))
        {
            return false;
        }
        else
        {
            this.username = username;
            this.password = password;
            accountNumber = ""+(int)(Math.random()*9000)+1000;
            return true;
        }
    }
    public boolean login(String username, String password)
    {
        if(username.equals("") || password.equals(""))
            return false;

        else if(username.equals(this.username) && password.equals(this.password))
           return true;
        else
            return false;
    }
    public boolean credit(int amount)
    {
        if(amount <= 0)
            return false;
        else
        {
            netAmount = netAmount + amount;
            return true;
        }
    }
    public boolean debit(int amount)
    {
        if(amount > netAmount || amount <= 0)
            return false;
        else
        {
            //netAmount = netAmount - amount;
            netAmount-=amount; // Compound Expressions
            return true;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBranch() {
        return branch;
    }

    public void setBranch(String branch) {
        this.branch = branch;
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getNetAmount() {
        return netAmount;
    }

    public void setNetAmount(int netAmount) {
        this.netAmount = netAmount;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }


 }


// Here Start the Test Class or a main method class


import javax.swing.JOptionPane;

public class TestBank
{
    public static void main(String[] args)
    {
        int choice;
        String name;
        String address;
        String branch;
        Bank b1 = null;
        String username;
        String password;

        int amount = 0;

        do
        {
            choice = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter your choice"
                                                                     + "\n 1 to create account"
                                                                     + "\n 2 to login"
                                                                     + "\n 3 to credit (+)"
                                                                     + "\n 4 to debit (-)"
                                                                     + "\n 0 to exit"));

            switch(choice)
            {
                case 1:
                    name = JOptionPane.showInputDialog(null,"Enter your name");
                    address = JOptionPane.showInputDialog(null,"Enter your address");
                    branch = JOptionPane.showInputDialog(null,"Enter your branch");
                    username = JOptionPane.showInputDialog(null,"Enter your username");
                    password = JOptionPane.showInputDialog(null,"Enter your password");

                    b1 = new Bank(name, address, branch);
                    if(b1.createUser(username, password))
                    {

                        JOptionPane.showMessageDialog(null,"Your user has been successfully created your username is " + b1.getUsername()
                            + "\n Your current balance is " + b1.getNetAmount() + " Account number is :" + b1.getAccountNumber());

                    }

                break;

                case 2:
                    username = JOptionPane.showInputDialog(null,"Enter your username");
                    password = JOptionPane.showInputDialog(null,"Enter your password");

                    if(b1.login(username, password))
                    {
                        JOptionPane.showMessageDialog(null,"Sucessfully logged in as " + b1.getUsername());
                    }
                    else
                        JOptionPane.showMessageDialog(null,"You can not login at this time","ERROR",JOptionPane.ERROR_MESSAGE);

                break;
                case 3:
                    amount = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter amount to credit"));
                    if(b1.credit(amount))
                    {
                        JOptionPane.showMessageDialog(null,"Amount of Rs." + amount+ " has been successfully added"
                                + "\n Net amount is " + b1.getNetAmount());
                    }
                    else
                        JOptionPane.showMessageDialog(null,"Amount of Rs. "+amount+ " can not be added","ERROR",JOptionPane.ERROR_MESSAGE);
                break;
                case 4:
                    amount = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter amount to credit"));
                    if(b1.debit(amount))
                    {
                        JOptionPane.showMessageDialog(null,"Amount of Rs." + amount+ " has been successfully deducted"
                                + "\n Net amount is " + b1.getNetAmount());
                    }
                    else
                        JOptionPane.showMessageDialog(null,"Amount of Rs. "+amount+ " can not be deducted","ERROR",JOptionPane.ERROR_MESSAGE);
                break;
                case 0:
                    JOptionPane.showMessageDialog(null,"Thank you for banking with us!");
                    System.exit(0);
                default:
                    JOptionPane.showMessageDialog(null,"ERROR in selecting choices","ERROR",JOptionPane.ERROR_MESSAGE);
            }


        } while(choice != 0);

    }
}

Screenshot - 10_16_2018 , 6_51_20 PM.jpg

Its a Banking application actually.

There are some bugs in it and I want them to Fix, but I am facing some problem.

I want Help.

Problem:   when you that application Step by Step. it work properly. like 

  1. Create your account,

  2. Login

and so on

but if you go Dicrect to the Option 2,3,4 etc, application Stops without giving some error message.

I want that halp that we I enter drectly to the Option 2 so it show me an error like ( Please First Create your account ) or if chose 3,4 it tells me that ( First Login ).

for this i want to fix that bug.

Hi Shaheer475,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our Community organized so users can more easily find information.

As you’ll notice, your Topic is now in the Project development help and advice board. No action is needed on your part; you can continue the conversation as normal here.

Let me know if you have any other questions or if I can help with anything else.

Cheers!

IESM2

Moderator