package com.hspedu.smallchange;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class smallchangeSys {
public static void main(String[] args) {
boolean loop = true;
Scanner scanner = new Scanner(System.in);
String key = "";
String details = "-------零钱通明细-------";
double money = 0;
double balance = 0;
Date date = null;//date是java。util。date类型,表示日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM--dd HH:MM");//用于日期格式化
String note = "";
do {
System.out.println("-----零钱通菜单-------");
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 = scanner.next();
switch (key) {
case "1":
System.out.println(details);
break;
case "2":
System.out.print("收益入账金额");
money = scanner.nextDouble();
if (money < 0) {
System.out.println("收益金额需要大于0");
break;
}
balance += money;
date = new Date();//获取当前日期
details += "\n收益入账\t+" + money + "\t" + sdf.format(date) + "\t" + balance;
break;
case "3":
System.out.println("消防消费");
money = scanner.nextDouble();
if(money<=0||money>balance){
System.out.println("你的消费金额应该在0-"+balance);
break;
}
System.out.println("消费声明");
note = scanner.next();
balance -= money;
date = new Date();
details += "\n" + note + "\t-" + money +" "+ sdf.format(date) + "\t" + balance;
break;
case "4":
String choice = "";
while (true) {
System.out.println("确定要退出吗?y/n");
choice = scanner.next();
if ("y".equals(choice) || "n".equals(choice)) {
break;
}
}
if ("y".equals(choice)) {
loop = false;
}
break;
default:
System.out.println("选择错误,请重新选择");
}
} while (loop);
System.out.println("-----退出了零钱通项目-----");
}
}
字符拼接版零钱通小项目
最新推荐文章于 2024-08-16 23:08:28 发布