package com.zhou.loose_change_application;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
public class HomePage {
//使用面向过程的方式完成小程序
//第一步:打印导航页面
public static void main(String[] args) {
//退出循环标志
boolean flag = true;
//存储明细信息
ArrayList<String> stringArrayList = new ArrayList<>();
//余额
double balance = 0.0;
Scanner scanner = new Scanner(System.in);
do {
System.out.println("-----------------零钱通菜单----------------");
System.out.println(" 1 零钱通明细");
System.out.println(" 2 收益入账");
System.out.println(" 3 消费");
System.out.println(" 4 退出");
System.out.print("请选择(1-4):");
int key = scanner.nextInt();
switch (key) {
case 1 -> {
System.out.println("-----------------零钱通明细-----------------");
if (stringArrayList.isEmpty())
System.out.println("暂无消费记录!");
else {
for (String log : stringArrayList)
System.out.println(log);
}
}
case 2 -> {
System.out.println("-----------------收益入账-----------------");
System.out.print("请输入入账金额:");
double rzje = scanner.nextDouble();
balance += rzje;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String rzsj = simpleDateFormat.format(new Date());
String minxi = "收益入账 +" + rzje + " " + rzsj + " 余额:" + balance;
stringArrayList.add(minxi);
}
case 3 -> {
System.out.println("-------------------消费-------------------");
System.out.print("请输入消费金额:");
double xfje = scanner.nextDouble();
balance -= xfje;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String xfsj = simpleDateFormat.format(new Date());
String minxi = "消费记录 -" + xfje + " " + xfsj + " 余额:" + balance;
stringArrayList.add(minxi);
}
case 4 -> {
System.out.println("退出");
flag = false;
}
default -> System.out.println("选择错误(1-4)");
}
} while (flag);
}
}
使用java基础,实现一个可以记录收益和消费记录等交互式小程序
最新推荐文章于 2023-11-22 09:53:36 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)