当前位置:网站首页>Household accounting procedures (First Edition)
Household accounting procedures (First Edition)
2022-06-26 05:49:00 【Wang Xiaoya】
Project requirement :
/*1. Suppose that the basic fund of family life is 10000 element
2. Income per registration ( menu 2) after , The amount of income should be added to the base Fund , And record the details of this income , For subsequent queries
3. Each registration expense ( menu 3) after , The amount of expenditure shall be deducted from the basic fund , And record the details of this expenditure , For subsequent queries .
4. Query revenue and expenditure details ( menu 1) when , All revenues will be displayed 、 Detailed list of expenditure names */
My implementation process :
Console output option after fine tuning process :


As shown in the figure ,\t : Horizontal tabulation (HT) ( Skip to the next TAB Location ) .\t Tabs each blank 8 Complete the current string length to 8 Integer multiple , You can adjust the position of the options until they are centered .


import java.util.Objects;
import java.util.Scanner;
/*1. Suppose that the basic fund of family life is 10000 element
2. Income per registration ( menu 2) after , The amount of income should be added to the base Fund , And record the details of this income , For subsequent queries
3. Each registration expense ( menu 3) after , The amount of expenditure shall be deducted from the basic fund , And record the details of this expenditure , For subsequent queries .
4. Query revenue and expenditure details ( menu 1) when , All revenues will be displayed 、 Detailed list of expenditure names */
public class FamilyLedger {
public static void main(String[] args) {
// Because of the use of hierarchical directories , So I will enter the steps I want to enter on the console , Import Scanner
Scanner sc = new Scanner(System.in);
System.out.println("---------------- Family income and expenditure accounting software -----------------");
System.out.println("\t\t\t\t1 Income and expenditure details ");
System.out.println("\t\t\t\t2 Registered income ");
System.out.println("\t\t\t\t3 Registration indication ");
System.out.println("\t\t\t\t4 refund Out ");
System.out.println(" Please select (1-4):");
int choice = sc.nextInt();
// Limit the scope
if (choice < 1 || choice > 4) {
System.out.println(" The content you entered is incorrect !");
}
// Because in addition to the initial capital fixed at the beginning , There will be dynamic changes in the future
// Initial bill
int start = 0;
if (choice == 1) {
Scanner a = new Scanner(System.in);
System.out.println(" Please enter the initial amount :");
start = a.nextInt();
}
// The income bill
int income = 0;
String source = "";
if (choice == 2) {
Scanner a = new Scanner(System.in);
System.out.println(" Please enter the revenue amount :");
System.out.println(" Please enter the source of income :");
income = a.nextInt();
source = a.next();
}
// Expense bills
int expenditure = 0;
String reason = "";
if (choice == 3) {
Scanner b = new Scanner(System.in);
System.out.println(" Please enter the expense amount :");
System.out.println(" Please enter the expense reason :");
expenditure = b.nextInt();
reason = b.next();
}
// Because it involves jumping to the corresponding menu , Here, select... In the process control statement switch sentence
switch (choice) {
case 1:
System.out.println("---------------- Your income and expenditure details ----------------");
System.out.println("\t\t\t\t Initial funding " + start + " element ");
break;
case 2:
System.out.println(" Income and expenditure \t" + " Total account amount \t\t" + " The amount of income \t\t" + " explain ");
System.out.println(" income \t" + (10000 + income) + "\t\t\t" + (+income) + "\t\t\t" + source);
break;
case 3:
System.out.println(" Income and expenditure \t" + " Total account amount \t\t" + " The amount of income \t\t" + " explain ");
System.out.println(" income \t" + (10000 - expenditure) + "\t\t\t" + (-expenditure) + "\t\t\t" + reason);
break;
case 4:
// Exit the screen
String exit = "";
Scanner c = new Scanner(System.in);
System.out.println(" Are you sure you want to exit this login interface ?");
System.out.println(" Definite exit (y)/ No , I'll think about it again (n):");
exit = c.next();
if (Objects.equals(exit, "y")) {
System.out.println(" You have exited the menu !");
return;
} else if (Objects.equals(exit, "n")) {
System.out.println(" You have entered the menu !");
break;
}
}
}
}
Output results :
Output 1 The situation of :
Output 2 The situation of :

Output 3 The situation of :

Output 4 The situation of :

边栏推荐
猜你喜欢

类和对象的学习

状态模式,身随心变

DOM document

Leetcode114. Expand binary tree into linked list

通俗易懂的从IDE说起,再谈谈小程序IDE

The State Council issued a document to improve the application of identity authentication and electronic seals, and strengthen the construction of Digital Government
转帖——不要迷失在技术的海洋中

Leetcode513. Find the value in the lower left corner of the tree

【 langage c】 stockage des données d'analyse approfondie en mémoire

Adapter mode
随机推荐
Using Jenkins to perform testng+selenium+jsup automated tests and generate extendreport test reports
pytorch(环境、tensorboard、transforms、torchvision、dataloader)
5分钟包你学会正则表达式
劣币驱逐良币的思考
The most refined language interprets the event dispatcher (also known as the event scheduler)
Command line interface of alluxio
REUSE_ALV_GRID_DISPLAY 事件实现(DATA_CHANGED)
操作符的优先级、结合性、是否控制求值顺序【详解】
小程序第三方微信授权登录的实现
Gram matrix
Project suspension
A new journey
Security problems in wireless networks and modern solutions
REUSE_ ALV_ GRID_ Display event implementation (data_changed)
Overloading and overriding
The difference between get and post in small interview questions
无线网络存在的安全问题及现代化解决方案
SQL query time period content
ZigBee learning in simple terms Lecture 1
Feelings of virtual project failure