Demo----小鲨鱼记账系统

Demo----小鲨鱼记账系统
        package com.company;
        import java.util.Scanner;
        public class Main {
            public static void main(String[] args) {
                // write your code here
                //这里必须要定义成员变量;否则其他循环中无法使用
                String detiale = "";
                double incomeNub = 0;
                //while中套子while;局部循环和大循环
                while (true) {
                    System.out.println("-------------欢迎使用小鲨鱼记账系统-------------");
                    System.out.println("1.收支明细");
                    System.out.println("2.登记明细");
                    System.out.println("3.登记支出");
                    System.out.println("4.退    出");
                    System.out.println("请输入你要选择的功能:");
                    Scanner sc = new Scanner(System.in);
                    int nextInt = sc.nextInt();
                    while (nextInt != 1 && nextInt != 2 && nextInt != 3 && nextInt != 4) {
                        System.out.println("你输入错误,请重新输入");
                        int newChose = sc.nextInt();
                        nextInt = newChose;
                    }
                    switch (nextInt) {
                        case 1:
                            System.out.println("记账系统--》》收支明细");
                            if(detiale.length()!=0){
                                System.out.println(detiale.substring(0,detiale.length()-1));
                        }else {
                            System.out.println(detiale);
                        }
                            break;
                        case 2:
                            System.out.println("记账系统--》》收入明细");
                            System.out.println("收入金额:");
                            double income = sc.nextDouble();
                            System.out.println("收入明细:");
                            String incomedeticle = sc.next();
                            incomeNub += income;
                            detiale = detiale+"收入金额:" + income + "收入明细:" + incomedeticle + ";账户余额:" + incomeNub+"\n";
                            break;
                        case 3:
                            System.out.println("记账系统--》》登记支出");
                            System.out.println("支出金额:");
                            double outcome = sc.nextDouble();
                            System.out.println("支出明细:");
                            String outcomedeticle = sc.next();
                            incomeNub -= outcome;
                            detiale = "支出金额:" + outcome + "支出明细:" + outcomedeticle + ";账户余额:" + incomeNub+"\n";
                            break;
                        case 4:
                            System.out.println("您是否要退出:YES/NO");
                            String bye = sc.next();
                            switch (bye) {
                                case "YES":
                                    System.out.println("感谢您的使用,期待下次继续使用");
                                    return;
                            }
                            break;
                    }
                }

            }
        }



       
       
posted @ 2022-04-25 10:33  爱豆技术部  阅读(112)  评论(0)    收藏  举报