一个过程化实现的零钱通面板
package SmallChangeSys;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
boolean flag = true;
Scanner scanner = new Scanner(System.in);
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
double balance = 0;
double money = 0;
String details = "\t" + " ---------零钱通明细---------";
while (flag) {
System.out.println("----------------零钱通菜单------------------");
System.out.println("\t" + "1 零钱通明细");
System.out.println("\t" + "2 收益入账");
System.out.println("\t" + "3 消费");
System.out.println("\t" + "4 退出");
System.out.print("请输入你的选项(1-4):");
int i = scanner.nextInt();
switch (i){
case 1:
System.out.println(details);
System.out.println("输入任意字符退出");
String next = scanner.next();
break;
case 2:
System.out.println("\t" + " 收益入账");
System.out.print("请输入你的收益:");
money = scanner.nextDouble();
balance += money;
details += "\n"+"收益入账"+"\t+"+money+"\t"+simpleDateFormat.format(date)+"\t"+"余额"+balance;
break;
case 3:
System.out.println("\t" + " 消费");
System.out.println("请输入你的消费金额:");
money = scanner.nextDouble();
System.out.println("请输入你消费的类型:");
if(balance < money){
System.out.println("余额不足!");
}
else{
balance -= money;
details += "\n"+scanner.next()+"\t"+"-"+money+"\t"+simpleDateFormat.format(date)+"\t"+"余额:"+balance;
}
break;
case 4:
System.out.println("\t" + " 已退出该系统");
flag = false;
break;
} }
}
}