零钱通OOP编程
package com.hspedu.smallchange.oop;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;public class SmallChangSysOOP {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="";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.退\t出");System.out.print("请选择1-4:");key=scanner.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 (loep);}public void detail(){System.out.println(deatils);}public void income(){System.out.print("收益入账金额:");money=scanner.nextDouble();if(money<=0){System.out.println("收益入账金额需要大于0");return;}balance+=money;rq=new Date();deatils+="\n收益入账\t+"+money+"\t"+sdf.format(rq)+"\t"+"金额:"+balance;}public void pay(){System.out.print("用户输入消费的金额");double xf=scanner.nextDouble();if(xf<=0||xf>balance){System.out.println("消费金额0-"+balance);return;}System.out.print("请输入消费说明");note=scanner.next();double a=balance-xf;deatils+="\n"+note+"\t-"+xf+"\t"+sdf.format(rq)+"\t"+"金额:"+a;}public void exit(){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;}}
}
package com.hspedu.smallchange.oop;
public class SmallChangSysAPP {public static void main(String[] args) {new SmallChangSysOOP().mainMenu();}
}