项目说明:
参照微信小程序的零钱通,可以完成收益入账,消费,查看明细,退出系统等功能。
以下是功能模块的具体代码:
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.Date;
public class first {
public static void main(String[] args) {
//第一个模块显示菜单
boolean loop = true;
double money = 0;//入账金额
double balance = 0;//余额
double cost = 0;//消费
String name;//消费名称
Date date;
date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh: mm");
String details = "----------零钱通明细---------";
Scanner scan = new Scanner(System.in);
do {
System.out.println("----------零钱通菜单---------");
System.out.println("\t\t\t\t1.零钱通明细\t\t\t\t");
System.out.println("\t\t\t\t2.收益入账\t\t\t\t");
System.out.println("\t\t\t\t3.消费\t\t\t\t");
System.out.println("\t\t\t\t4.退 出\t\t\t\t");
System.out.println("请选择(1-4):");
int key = scan.nextInt();
switch (key) {
case 1:
System.out.println(details + "\n");
break;
case 2:
do {
System.out.println("请输入入账金额");
money = scan.nextDouble();
if (money > 0) {
balance += money;
} else {
System.out.println("money输入有误,请重新输入:");
}
} while (money < 0);
details += "\n" + "收益入账\t+" + money + "\t" + sdf.format(date) + "\t" + balance;
// System.out.println("---------2.收益入账-----------");
break;
case 3:
System.out.println("请输入消费名称:");
name = scan.next();
do {
System.out.println("请输入消费金额:");
cost = scan.nextDouble();
if (cost > 0) {
balance -= cost;
} else {
System.out.println("cost输入有误,请重新输入:");
}
} while (cost < 0);
details += "\n-" + name + "\t" + cost + "\t" + sdf.format(date) + "\t" + balance;
break;
case 4:
System.out.println("你确定要退出吗?y/n");
char ans = scan.next().charAt(0);
if (ans == 'y') {
loop = false;
} else if (ans == 'n') {
System.out.println("请重新选择(1-4):");
} else System.out.println("输入有误,请重新输入:(y/n)");
break;
default:
System.out.println("输入有误,请重新输入");
}
} while (loop);
System.out.println("退出零钱通");
}
}
部分功能模块代码运行展示:
标签:java,--,money,System,零钱,cost,println,输入,out From: https://blog.csdn.net/2302_79648928/article/details/142903589