当我的取款输入大于我的现金余额时,如何打印错误信息?

How to print error message when my withdraw input is greater than my cash balance?

我的 java 银行程序有问题,在该程序中用户可以从现金余额中提取较大的部分。我的其他功能 "Payment" 和 "Send Money" 也是如此。我如何使用此代码和 'else if' 语句或???我很难过。请帮忙。谢谢

case "Withdraw": //withdraw money from account
            if(people.get(accIndex).getMoney()<=0) { //if the user does not have enough funds
                JOptionPane.showMessageDialog(null, "You Dont Have Enough Funds In Your Account!", "Javank", JOptionPane.WARNING_MESSAGE);
            }
            else {
            System.out.print("Input amount to withdraw: ");
            double withmoney = in.nextDouble();
            people.get(accIndex).setMoney(people.get(accIndex).getMoney()-withmoney); //gets info from accIndex and withdraws money from account
            JOptionPane.showMessageDialog(null, "Successfully withdrew: "+withmoney,"Javank",JOptionPane.INFORMATION_MESSAGE);
            LocalDateTime myDateObj2 = LocalDateTime.now(); //create local date and time object
            String formattedDate2 = myDateObj2.format(myFormatObj); //store it to a string (formatted)
            checktrans.push("Withdrew "+withmoney+" @ "+formattedDate2); //add to transaction stack
            }
            break;

我认为如果用户在开始时余额为正,则无关紧要。 相反,如果请求的金额已被提取,我会检查余额是否会低于零。

类似

double withmoney = in.nextDouble();
if((people.get(accIndex).getMoney() - withmoney) < 0.0) {
    //the user does not have enough funds
}
else {
    //allow withdrawal
}