当前位置:网站首页>家庭记账程序(第一版)
家庭记账程序(第一版)
2022-06-26 05:42:00 【王小小鸭】
项目要求:
/*1.假设家庭起始的生活基本金为10000元
2.每次登记收入(菜单2)后,收入的金额应累加到基本金上,并记录本次收入明细,以便后续的查询
3.每次登记支出(菜单3)后,支出的金额应从基本金中扣除,并记录本次支出明细,以便后续的查询。
4.查询收支明细( 菜单1)时,将显示所有的收入、支出名细列表 */
我的实现过程:
控制台输出选项后微调过程:


如图所示,\t :横向制表(HT) (跳到下一个TAB位置) 。\t制表符每个空8个补全当前字符串长度到8的整数倍,可以调整选项位置直至居中。


import java.util.Objects;
import java.util.Scanner;
/*1.假设家庭起始的生活基本金为10000元
2.每次登记收入(菜单2)后,收入的金额应累加到基本金上,并记录本次收入明细,以便后续的查询
3.每次登记支出(菜单3)后,支出的金额应从基本金中扣除,并记录本次支出明细,以便后续的查询。
4.查询收支明细( 菜单1)时,将显示所有的收入、支出名细列表 */
public class FamilyLedger {
public static void main(String[] args) {
// 因为使用分级目录,所以会在控制台输入想进入的步骤,导入Scanner
Scanner sc = new Scanner(System.in);
System.out.println("----------------家庭收支记账软件-----------------");
System.out.println("\t\t\t\t1 收支明细");
System.out.println("\t\t\t\t2 登记收入");
System.out.println("\t\t\t\t3 登记指出");
System.out.println("\t\t\t\t4 退 出");
System.out.println("请选择(1-4):");
int choice = sc.nextInt();
// 限定范围
if (choice < 1 || choice > 4) {
System.out.println("您输入的内容有误!");
}
//因为除了一开始初始资金固定,后面都会有动态变化
//初始账单
int start = 0;
if (choice == 1) {
Scanner a = new Scanner(System.in);
System.out.println("请输入初始金额:");
start = a.nextInt();
}
//收入账单
int income = 0;
String source = "";
if (choice == 2) {
Scanner a = new Scanner(System.in);
System.out.println("请输入收入金额:");
System.out.println("请输入收入来源:");
income = a.nextInt();
source = a.next();
}
//支出账单
int expenditure = 0;
String reason = "";
if (choice == 3) {
Scanner b = new Scanner(System.in);
System.out.println("请输入支出金额:");
System.out.println("请输入支出原因:");
expenditure = b.nextInt();
reason = b.next();
}
//因为涉及跳转对应菜单,这里选择流程控制语句中的switch语句
switch (choice) {
case 1:
System.out.println("----------------您的收支明细----------------");
System.out.println("\t\t\t\t初始资金" + start + "元");
break;
case 2:
System.out.println("收支\t" + "账户总金额\t\t" + "收入金额\t\t" + "说明");
System.out.println("收入\t" + (10000 + income) + "\t\t\t" + (+income) + "\t\t\t" + source);
break;
case 3:
System.out.println("收支\t" + "账户总金额\t\t" + "收入金额\t\t" + "说明");
System.out.println("收入\t" + (10000 - expenditure) + "\t\t\t" + (-expenditure) + "\t\t\t" + reason);
break;
case 4:
//退出界面
String exit = "";
Scanner c = new Scanner(System.in);
System.out.println("请问您确定要退出此登录界面吗?");
System.out.println("确定退出(y)/不,我再想想(n):");
exit = c.next();
if (Objects.equals(exit, "y")) {
System.out.println("您已退出菜单!");
return;
} else if (Objects.equals(exit, "n")) {
System.out.println("您已进入菜单!");
break;
}
}
}
}
输出结果:
输出1的情况:
输出2的情况:

输出3的情况:

输出4的情况:

边栏推荐
- C XX management system
- Could not get unknown property ‘*‘ for SigningConfig container of type org.gradle.api.internal
- 一段不离不弃的爱情
- BOM文档
- Life is so fragile
- Introduction to GUI programming to game practice (II)
- Introduction to lcm32f037 series of MCU chip for motor
- one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
- 机器学习 07:PCA 及其 sklearn 源码解读
- REUSE_ ALV_ GRID_ Display event implementation (data_changed)
猜你喜欢

cartographer_ optimization_ problem_ 2d

Bingc (inheritance)

AutowiredAnnotationBeanPostProcessor什么时候被实例化的?

Gram 矩阵

11 IO frame

使用Jenkins执行TestNg+Selenium+Jsoup自动化测试和生成ExtentReport测试报告

cartographer_ backend_ constraint

Command line interface of alluxio

Ribbon load balancing service call
![[arm] add desktop application for buildreoot of rk3568 development board](/img/9a/28015cdea7362261c39ffc7f6e13a9.png)
[arm] add desktop application for buildreoot of rk3568 development board
随机推荐
cartographer_ pose_ graph_ 2d
kolla-ansible部署openstack yoga版本
项目中止
定位设置水平,垂直居中(多种方法)
ZigBee explain in simple terms lesson 2 hardware related and IO operation
Pytorch (network model)
[C language] deep analysis of data storage in memory
Lesson 4 serial port and clock
力扣 875. 爱吃香蕉的珂珂
ZigBee learning in simple terms lesson 3 external interruption
Data storage: the difference between MySQL InnoDB and MyISAM
生命原来如此脆弱
vscode config
Wechat team sharing: technical decryption behind wechat's 100 million daily real-time audio and video chats
Navicat如何将当前连接信息复用另一台电脑
Describe an experiment of Kali ARP in LAN
The most refined language interprets the event dispatcher (also known as the event scheduler)
Introduction to GUI programming to game practice (II)
机器学习 05:非线性支持向量机
Learn cache lines and pseudo sharing of JVM slowly