当前位置:网站首页>简易零钱通
简易零钱通
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 ;
}
}
边栏推荐
- [matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
- Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
- appliedzkp zkevm(13)中的Public Inputs
- 空洞卷积、可变形卷积、可变形ROI Pooling
- Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
- c语言经典指针和数组笔试题解析
- Yyds dry goods inventory TCP & UDP
- 练习-冒泡排序
- 【MATLAB】MATLAB 仿真模拟调制系统 — SSB 系统
- [paper summary] zero shot semantic segmentation
猜你喜欢

Unity 接入天气系统

KMP match string

Secondary vocational group network security - memory Forensics

TCP state transition diagram

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

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

2022年A特种设备相关管理(电梯)考试题模拟考试平台操作

Sécurité du réseau dans les écoles professionnelles secondaires - preuve de mémoire

STM32F1与STM32CubeIDE编程实例-74HC595驱动4位7段数码管

Integer type of C language
随机推荐
COMP1721 Creating Classes
简单g++和gdb调试
June 2022 summary
We believe that the development of consumer Internet will still be limited to the Internet industry itself
基于单片机的太阳能杀虫系统
[matlab] general function of communication signal modulation Fourier transform
Exercise bubble sort
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
C basic (VII) document operation
Li Kou's 300th weekly match
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)
Unity is connected to the weather system
Yyds dry goods inventory TCP & UDP
2022 t elevator repair operation certificate examination question bank and simulation examination
cmake
【MATLAB】通信信号调制通用函数 — 带通滤波器
A summary of the 8544 problem that SolidWorks Standard cannot obtain a license
appliedzkp zkevm(13)中的Public Inputs
定制一个自己项目里需要的分页器
Get the ID of the record just inserted from laravel