package SmallChangeSys;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
boolean flag = true;
Scanner scanner = new Scanner(System.in);
double balance = 0;
double money = 0;
Person person = new Person();
while (flag) {
System.out.println("----------------零钱通菜单------------------");
System.out.println("\t" + "1 零钱通明细");
System.out.println("\t" + "2 收益入账");
System.out.println("\t" + "3 消费");
System.out.println("\t" + "4 退出");
System.out.print("请输入你的选项(1-4):");
int i = scanner.nextInt();
switch (i){
case 1:
person.detail();
break;
case 2:
person.income();
break;
case 3:
person.spend();
break;
case 4:
flag = person.quit();
break;
} }
}
}
class Person{
double money;
double balance;
String details = "\t" + " ---------零钱通明细---------";
Scanner next1 = new Scanner(System.in);
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
public void detail(){
System.out.println(details);
System.out.println("输入任意字符退出");
String next = next1.next();
}
public void income(){
System.out.println("\t" + " 收益入账");
System.out.print("请输入你的收益:");
money = next1.nextDouble();
balance += money;
details += "\n"+"收益入账"+"\t+"+money+"\t"+simpleDateFormat.format(date)+"\t"+"余额"+balance;
}
public void spend(){
System.out.println("\t" + " 消费");
System.out.println("请输入你的消费金额:");
money = next1.nextDouble();
System.out.println("请输入你消费的类型:");
if(balance < money){
System.out.println("余额不足!");
}
else{
balance -= money;
details += "\n"+next1.next()+"\t"+"-"+money+"\t"+simpleDateFormat.format(date)+"\t"+"余额:"+balance;
}
}
public boolean quit(){
System.out.println("\t" + " 你确定要退出吗?(y/n)");
String next = next1.next();
if(next.equals("y")){
System.out.println("已退出零钱通系统,欢迎下次使用");
return false;
}
else if(next.equals("n")){
return true;
}
else{
System.out.println("下次请输入正确的指令!");
return true;
}
}
}
零钱通(javaoop版本)
最新推荐文章于 2024-08-24 17:09:16 发布