当前位置:网站首页>简易零钱通
简易零钱通
2022-07-04 04:55:00 【fanlangke】
来源:韩顺平 零基础30天学会Java
SmallChangeSysAPP
package com.hspedu.smallchange.oop;
import com.hspedu.smallchange.SmallChangeSys;
public class SmallChangeSysAPP {
public static void main(String[] args) {
new SmallChangeSysOOP().mainMenu();
}
}
SmallChangeSysOOP
package com.hspedu.smallchange.oop;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class SmallChangeSysOOP {
boolean loop = true;
Scanner scanner = new Scanner(System.in);
String key = "";
String details = "----------零钱通明细----------";
double money = 0;
double balance = 0;
Date date = null;
String note = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
public void mainMenu() {
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.println("请选择(1-4):");
this.key = this.scanner.next();
switch (this.key) {
case "1":
this.detail();
break;
case "2":
this.income();
break;
case "3":
this.pay();
break;
case "4":
this.exit();
break;
default:
System.out.println("选择有误,请重新选择");
}
}while(loop);
System.out.println("-----退出了零钱通项目-----");
}
public void detail(){
System.out.println(details);
}
public void income(){
System.out.println("收益入账金额:");
money=scanner.nextDouble();
if(money<0){
System.out.println("收益入账金额不能小于0");
return;
}
balance+=money;
date =new Date();
details+="\n收益入账\t+"+money+"\t"+sdf.format(date);
}
public void pay(){
System.out.println("消费金额:");
money=scanner.nextDouble();
if(money<0||money>balance){
System.out.println("收益入账金额不能小于0");
return;
}
System.out.println("消费说明:");
note=scanner.next();
balance-=money;
date =new Date();
details+="\n"+note+"\t-"+money+"\t"+sdf.format(date);
}
public void exit(){
String choice="";
while(true){
System.out.println("你确定要退出吗?y/n");
choice=scanner.next();
if(choice.equals("y")||choice.equals("n")){
break;
}
}
if(choice.equals("n")){
return ;
}
loop=false;
return ;
}
}
边栏推荐
- Zkevm (12) state proof of appliedzkp
- Simulink与Arduino串口通信
- [matlab] general function of communication signal modulation bandpass filter
- 《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记
- 拓扑排序和关键路径的图形化显示
- Zhongke panyun-d module analysis and scoring standard
- [matlab] matlab simulation modulation system - DSB system
- 中科磐云—2022广西逆向解析思路
- [matlab] matlab simulates digital bandpass transmission systems - QPSK and OQPSK systems
- A summary of the 8544 problem that SolidWorks Standard cannot obtain a license
猜你喜欢

Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it

LabVIEW错误对话框的出现

2022 Guangdong provincial competition - code information acquisition and analysis flag

Detailed comparison of Hynix emmc5.0 and 5.1 series

Evolution of system architecture: differences and connections between SOA and microservice architecture

2022年R2移动式压力容器充装复训题库及答案

2022年6月总结

全国职业院校技能大赛(中职组)网络安全竞赛试题—解析

PostgreSQL has officially surpassed mysql. Is this guy too strong!

Character types of C language
随机推荐
【无标题】
VSCode的有用插件
中职组网络安全—内存取证
[matlab] matlab simulation modulation system - DSB system
2022危险化学品经营单位安全管理人员上岗证题库及答案
[matlab] general function of communication signal modulation bandpass filter
[matlab] matlab simulation modulation system FM system
Li Kou's 300th weekly match
拓扑排序和关键路径的图形化显示
[matlab] matlab simulation - simulate the AM modulation process of the modulation system
appliedzkp zkevm(11)中的EVM Proof
Share some of my telecommuting experience
Annex 4: scoring criteria of the attacker docx
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
[matlab] matlab simulates digital bandpass transmission systems - QPSK and OQPSK systems
With the advent of the IP era, how can E-sports hotels take advantage of the "east wind" of games?
[matlab] communication signal modulation general function interpolation function
如何构建属于自己的知识引擎?社群开放申请
【QT】定时器
【MATLAB】MATLAB 仿真数字基带传输系统 — 双极性基带信号(第 I 类部分响应波形)的眼图