生活随笔
收集整理的這篇文章主要介紹了
项目-零钱通
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
項目-零錢通
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("-------退出了,零錢通菜單------");}
}
總結
以上是生活随笔為你收集整理的项目-零钱通的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。