【无标题】JAVA

package com.hspedu.smallchange.oop_;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSysOOP {
    String key;
    String details = "------------零钱通明细------------";
    boolean loop = true;
    double money = 0;
    double balance = 0;
    Date date = null;
    String note = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");//可用于日期格式化
    Scanner S = new Scanner(System.in);
    public void mainMenu(){
        do {
            System.out.println("=====零钱通菜单OOP=====");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退    出");
            System.out.println("请选择(1-4): ");
            key = S.next();
            switch (key){
                case "1":
                    this.detail();
                    break;
                case "2":
                   this.income();
                   break;
                case "3":
                   this.pay();
                   break;
                case "4":
                    this.exit();
                    break;
                default:
                    System.out.println("选择有误,重选");
            }
        }while (loop);
    }
    public void detail(){
        System.out.println(details);
    }
    public void income(){
        System.out.println("收益入账金额 :");
        money = S.nextDouble();
        if(money <= 0){
            System.out.println("收益入账金额需要大于0");
            return;
        }
        balance += money;
        date = new Date();
        details += "\n收益入账\t+" + money + "\t" + sdf.format(date) + "\t" + balance;
    }
    public void pay(){
        System.out.println("消费金额:");
        money = S.nextDouble();
        if (money <=0 || money > balance){
            System.out.println("你的消费金额应该在0-"+balance);
            return;
        }
        System.out.println("消费说明:");
        note = S.next();
        balance -= money;
        date = new Date();
        details += "\n" + note + "\t-" + money +"\t"+ sdf.format(date) + "\t" + balance;
    }
    public void exit(){
        String choice = "";
        while (true){
            System.out.println("你确定要退出吗? y/n");
            choice = S.next();
            if ("y".equals(choice)||"n".equals(choice)){
                return;
            }
        }
    }
}

==================================================================================================================================================

package com.hspedu.smallchange.oop_;

public class SmallChangeSysApp {
    public static void main(String[] args){
        System.out.println("====欢迎来到DJ联盟====");
        new SmallChangeSysOOP().mainMenu();
    }
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值