Simple ATM source code and operating results

Code exercise

Simple ATM
topic description:
There are 100 yuan in it.
If you save money, use the input amount plus the amount you deposited first, and then display the balance prompt box.
If you withdraw money, subtract the amount of money withdrawn, and then display the balance prompt box.
If the balance is displayed, output the balance.
If you exit, display Exit the information prompt box
Code display:

package zuoye;

import java.util.Scanner;

public class t03 {
    
    
    public static void main(String[] args) {
    
    
        double money=100;
        while (true){
    
    
            System.out.println("请输入你想办理的业务:");
            Scanner scanner = new Scanner(System.in);
            String yewu = scanner.next();
            if (yewu.equals("存钱")){
    
    
                System.out.println("请输入存钱金额:");
                double money1 = scanner.nextDouble();
                money=money+money1;
                System.out.println("卡上余额为:"+money);
                System.out.println("是否继续办理业务:");
                String next = scanner.next();
                if (next.equals("是")){
    
    
                    System.out.println("请重新选择您想办理的业务");
                }else {
    
    
                    System.out.println("退出系统");

                }
            }else if (yewu.equals("取钱")){
    
    
                System.out.println("请输入取款金额:");
                double money2 = scanner.nextDouble();
                if (money2<=money&&money2>0){
    
    
                    money=money-money2;
                    System.out.println("卡上余额为:"+money);
                    System.out.println("是否继续办理业务:");
                    String next = scanner.next();
                    if (next.equals("是")){
    
    
                        System.out.println("请重新选择您想办理的业务");
                    }else {
    
    
                        System.out.println("退出系统");
                        break;
                    }
                }else {
    
    
                    System.out.println("卡上余额不足,无法取款");
                }
            }
        }
    }
}

Operating results show:
save:
Insert picture description here
withdraw money:
Insert picture description hereNote: Code Description
deposit when you can not switch directly to the teller, the two functions are separate; if you switch to directly deposit withdrawals, Cary amount is still 100, rather than keep you too The amount after the money.

Guess you like

Origin blog.csdn.net/tan1024/article/details/109784250