用java面向对象写一个简单的增加查询
功能是实现不是很标准,有空再改改
package SourceCode.OOP;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class MenuOOP {
Scanner scanner = new Scanner(System.in);
boolean loop = true;
double Earnings = 0;
double balance = 0;
double pay = 0;
String details ;
String Cons = null;
SimpleDateFormat ChinaTime = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date date = new Date();
public void selectMenu(){
do{
System.out.println("\n----------------菜单----------------");
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.println("请输入(1-4): ");
String menu = scanner.next();
switch (menu){
case "1":{
this.Detail();
break;
}
case "2":{
this.EarningsBooked();
break;
}
case "3":{
this.Consumption();
break;
}
case "4":{
this.Exit();
loop = false;
break;
}
}
}while (loop);
}
public void Detail(){
System.out.println( "----------------零钱通明细----------------");
System.out.println("");
System.out.println(details);
}
public void Consumption(){
System.out.println("请输入消费用于:");
Cons = scanner.next();
System.out.println("请输入消费了多少钱:");
pay = scanner.nextDouble();
balance = balance - pay;
details += "\n"+Cons + "\t" +ChinaTime.format(date)+ "\t"+ "余额:" + balance;
System.out.println();
System.out.println(details );
}
public void EarningsBooked(){
System.out.println("请输入入账金额: ");
Earnings = scanner.nextDouble();
balance += Earnings;
details += "\n收益: " +"+"+Earnings+"\t\t" +ChinaTime.format(date)+"\t"+"余额: "+balance;
System.out.println();
System.out.println(details);
}
public void Exit(){
System.out.println("退出成功-------");
}
}
实现类
package SourceCode.OOP;
public class MenuOOP_Main {
public static void main(String[] args) {
MenuOOP menuOOP = new MenuOOP();
menuOOP.selectMenu();
}
}
运行结果:
"C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" "-javaagent:C:\Users\滔\Desktop\暑假实训\idea\IntelliJ IDEA 2020.2\lib\idea_rt.jar=52651:C:\Users\滔\Desktop\暑假实训\idea\IntelliJ IDEA 2020.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_191\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar;C:\Users\滔\IdeaProjects\Test1\out\production\Test1" SourceCode.OOP.MenuOOP_Main
----------------菜单----------------
1 零钱通明细
2 收益入账
3 消费
4 退出
请输入(1-4):
3
请输入消费用于:
3
请输入消费了多少钱:
3
null
3 2021-08-26 23:30 余额:-3.0
----------------菜单----------------
1 零钱通明细
2 收益入账
3 消费
4 退出
请输入(1-4):
3
请输入消费用于:
3
请输入消费了多少钱:
3
null
3 2021-08-26 23:30 余额:-3.0
3 2021-08-26 23:30 余额:-6.0
----------------菜单----------------
1 零钱通明细
2 收益入账
3 消费
4 退出
请输入(1-4):
4
退出成功-------
|