package SmallChangeSys;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class SmallChangeSys {
//化繁为简
//1.先完成显示菜单 并可以选择菜单,给出对应显示
//2.完成零钱通明细
//(1)可以把收益入账和消费,保存到数组 (2)可以使用对象 (3)简单的话可以使用String拼接
//3.收益入账
//定义新的变量
//4.消费
public static void main(String[] args) {
boolean loop = true;
Scanner scanner = new Scanner(System.in);
String key = "";
String details = "----------零钱通明细-------------\n";
double money = 0;
double balance = 0;
String note = "";
Date date = null; //表示日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");//可用于日期格式化
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 分支控制
switch (key){
case "1" :
System.out.println(details);
break;
case "2" :
System.out.println("收益入帐金额");
money = scanner.nextDouble();
//money 的值范围应该校验 --> 一会再完善
balance += money;
//拼接收益入账信息到details
date = new Date();
details += "\n收益入账\t"+ money + "\t" + sdf.format(date) + "\t" + balance;
break;
case "3" :
System.out.println("消费金额");
money = scanner.nextDouble();
//money 的值范围应该校验 --> 一会再完善
System.out.println("消费说明");
note = scanner.next();
balance -= money;
date = new Date();
details += "\n"+ note + "\t-" + money + "\t" + sdf.format(date) + "\t" + balance;
break;
case "4" :
System.out.println("4 退 出");
loop = false;
break;
default:
System.out.println("选择有误,请重新选择");
}
}while (loop);
System.out.println("--------退出了零钱通项目---------");
}
}
添加消费功能