项目-零钱通
package com.hspedu.smallchange;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;public class SmallCanapeSays {public static void main(String[] args) {boolean loep=true;Scanner scanner=new Scanner(System.in);String key="";String deatils="\n========零钱通明细==========";double money=0;double balance=0;Date rq=null;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.退\t出");System.out.print("请选择1-4:");key=scanner.next();switch (key){case "1":System.out.println(deatils);break;case "2":System.out.print("收益入账金额:");money=scanner.nextDouble();if(money<=0){System.out.println("收益入账金额需要大于0");break;}balance+=money;rq=new Date();deatils+="\n收益入账\t+"+money+"\t"+sdf.format(rq)+"\t"+"金额:"+balance;break;case "3":System.out.print("用户输入消费的金额");double xf=scanner.nextDouble();if(xf<=0||xf>balance){System.out.println("消费金额0-"+balance);break;}System.out.print("请输入消费说明");note=scanner.next();double a=balance-xf;deatils+="\n"+note+"\t-"+xf+"\t"+sdf.format(rq)+"\t"+"金额:"+a;break;case "4":String choice="";while (true){System.out.println("你确定要退出吗?y/n");choice=scanner.next();if("y".equals(choice)||"n".equals(choice)){break;}else {System.out.println("请重新输入");}}if(choice.equals("y")){loep=false;}break;default:System.out.println("输入有误");}}while (loep);System.out.println("-------退出了,零钱通菜单------");}
}