Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i needed to make a banking app on java and i keep getting an erro but have no idea where its coming from

What I have tried:

Java
import javax.swing.*;
public class BankApp
{
   
    public static void main (String[] args) 
    {
        double bal; // Balance of savings account
        int sel = 0; // Menu selection

        bal = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter your Account Number :", "Welcome To Nakeisha's Bank",JOptionPane.QUESTION_MESSAGE));

        while (sel != 4)
        {
            sel = Integer.parseInt(JOptionPane.showInputDialog(null, """
                                                                     Select an option: 
                                                                     1. Withdraw 
                                                                     2. Deposit 
                                                                     3. Check balance 
                                                                     4. Exit"""));

            switch(sel)
            {
                case 1 -> withdraw(bal);

                case 2 -> deposit(bal);

                case 3 -> CheckBalance(bal);

                default -> {
                        JOptionPane.showMessageDialog(null, "Thank you for using Nakeisha's Bank.");
                        System.exit(0);
                }
            }
        }
    }

    public static double withdraw (double bal)
    {
        double withdrawAmt; // Amount to withdraw

        withdrawAmt = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the amount you want to withdraw (in R):", "Withdrawals", JOptionPane.QUESTION_MESSAGE));

        while (bal < withdrawAmt)
        {
            JOptionPane.showMessageDialog(null, "The amount you have entered is more than your savings balance.\nPlease re-enter.", "Withdrawals", JOptionPane.ERROR_MESSAGE);
            withdrawAmt = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter amount to withdraw (in R):", "Withdrawals", JOptionPane.QUESTION_MESSAGE));
        }
        bal -= withdrawAmt;
        return bal;
    }

    public static double deposit (double bal)
    {
        double depositAmt; // Amount to deposit

        depositAmt = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the amount you want to deposit (in R):", "Deposits", JOptionPane.QUESTION_MESSAGE));

        while (depositAmt <= 0)
        {
            JOptionPane.showMessageDialog(null, "The amount you have entered is a negative amount or zero.\nPlease re-enter.", "Deposits", JOptionPane.ERROR_MESSAGE);
            depositAmt = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the amount you want to deposit (in R):", "Deposits", JOptionPane.QUESTION_MESSAGE));
        }
        bal += depositAmt;
        return bal;
    }

    public static void CheckBalance (double bal)
    {
        JOptionPane.showMessageDialog(null, "Your balance is: R" +bal, "Check Balance", JOptionPane.INFORMATION_MESSAGE);
    }

}
Posted
Updated 16-Nov-22 2:46am
v3
Comments
wseng 16-Nov-22 2:58am    
please show us your code
CHill60 16-Nov-22 2:58am    
Share the code you have tried and tell us what the errors are, and we will try to help you fix it. But we are not going to write your assignment for you
Dave Kreskowiak 16-Nov-22 8:48am    
and the exact error message would be .... ? Hint: Very important for solving the problem.

This is not a code writing service.
No one here is going to do your homework.
If we did you would learn nothing.

When you tried something yourself
please come back and show us what you achieved so far.
 
Share this answer
 
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
See Trail: Creating a GUI With Swing (The Java™ Tutorials)[^] for help with creating a basic GUI application.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900