各功能的实现
import java.util.Date; import java.util.Scanner; public class SmallChanageSys { //创建相关对象 Scanner scanner = new Scanner(System.in); Date date = new Date(); //接收零钱通明细的结果 String result = ""; //接收输入的金额 double money = 0; //接收余额 double balance = 0; //定义datestr接收当前日期时间,格式为年-月-日 时:分:秒 String str1 = String.format("%tF", date); String str2 = String.format("%tT", date); String datestr = str1 + "t" + str2; //显示菜单 public void mainMenu() { System.out.println("==========零钱通菜单=========="); System.out.println("1 零钱通明细"); System.out.println("2 收益入账"); System.out.println("3 消 费"); System.out.println("4 退出系统"); } //零钱通的明细 public void detail() { if (result.equals("")) { System.out.println("无记录可查,请先添加记录后再查询!"); } else { System.out.println("------------------零钱通明细------------------" + result + "n"); } } //收益入账 public void income() { System.out.println("请输入收益入账金额:"); money = scanner.nextDouble(); balance += money; //date = new Date(); //result += "n收益入账t+"+money+"t"+sdf.format(date)+"t余额t"+balance; result += "n收益入账t+" + money + "t" + datestr + "t余额t" + balance; } //消 费 public void pay() { System.out.println("该账户余额为:" + balance); System.out.println("请输入消费出账金额:"); money = scanner.nextInt();//expend支出 if (money > balance) { System.out.println("对不起,余额已不足无法支出!"); return; } balance -= money; result += "n消费出账t-" + money + "t" + datestr + "t余额t" + balance; } public void exit() { System.out.println("正在进行微信零钱通系统退出->->->n"); //给此系统评分 System.out.println("感谢对此系统的使用,请给出您宝贵的评价(按enter键确认):"); int score = scanner.nextInt(); System.out.println("已经收到您给出宝贵的" + score + "分啦!!!n"); System.out.println("微信零钱通系统正在退出中......nn感谢对此系统的使用,欢迎下次光临!"); return; //输入1退出系统 } }主界面实现
import java.util.Scanner; public class textMain { public static void main(String[] args) { //创建相关对象 Scanner scanner = new Scanner(System.in); SmallChanageSys oop = new SmallChanageSys(); int key = 0; while (true) { oop.mainMenu(); System.out.println("请输入你的选择(1-4):"); key = scanner.nextInt(); switch (key) { //零钱通明细 case 1: oop.detail(); break; //收益入账 case 2: oop.income(); break; //消 费 case 3: oop.pay(); break; //退出系统 case 4: oop.exit(); return; //输入有误给出提示 default: System.out.println("菜单项选择有误,请重新输入:"); } } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)