package change;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Change {
public static void main(String[] args) {
boolean loop = true;
Scanner scanner = new Scanner(System.in);
String key = "";
// 明细
String details = "-------------明细--------------\n";
// 入账
double money = 0;
double balance = 0;
Date date = null;
// 将获取的时间格式化成我们想要的格式
SimpleDateFormat tf = 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 退出");
System.out.print("请选择(1-4): ");
key = scanner.next();
switch(key){
case "1" :
System.out.println(details);
break;
case "2" :
System.out.print("请输入您的金额:");
money = scanner.nextDouble();
if (money <= 0) {
System.out.println("金融应该大于0哦");
break;
}
balance += money;
date = new Date();
details += "入账金额" + "\t" + money + "\t"
+ tf.format(date) + "\t" + "余额"
+ "\t" + balance + "\n";
break;
case "3" :
System.out.print("消费金额: ");
money = scanner.nextDouble();
if (money <= 0 || money > balance) {
System.out.println("金额的范围是 0 - " + balance);
break;
}
balance -= money;
System.out.print("消费说明:");
note = scanner.next();
date = new Date();
details += note + "\t" + money + "\t"
+ tf.format(date) + "\t" + "余额"
+ "\t" + balance + "\n";
break;
case "4" :
String choice = "";
while (true){
System.out.println("您确定要退出吗?y/n");
choice = scanner.next();
if ("y".equals(choice) || "n".equals(choice)){
break;
}
}
if (choice.equals("y")){
loop = false;
}
break;
default:
System.out.println("输入有误,请重新输入");
}
System.out.println("++++++++++++++++++++++++++++++++");
}while(loop);
System.out.println("您已经退出零钱通系统");
}
}
标签:java,scanner,System,零钱,String,版本,println,out
From: https://www.cnblogs.com/liudelantu/p/17629619.html