当前位置:网站首页>Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)
Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)
2022-07-04 07:29:00 【Inter personal liabilities^】
Family accounting software
1. The goal is
Simulate the implementation of a text-based interface 《 Family accounting software 》
Master preliminary programming and debugging skills
It mainly involves the following knowledge points
- Definition of variables
- Use of basic data types
- Loop statement
- Branch statement
- Method statement 、 Reception of call and return values
- Simple screen output format control
2. Requirement specification
- The simulation is based on the text interface 《 Family accounting software 》
- The software can record the family's income 、 spending , And can print revenue and expenditure details
- The project adopts hierarchical menu .
The main menu
Simulation steps
- Suppose the initial life principal of the family is 10000 element
- 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
- 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
- Query revenue and expenditure details ( menu 1) when , All revenues will be displayed , List of expenditure details
Registered income
Register expenses
Income and expenditure details
Alignment of parts list , You can simply use tabs ‘\t’ To achieve
sign out
3. Code details
Tool class
package project;
import java.util.Scanner;
/** Utility Tool class : Encapsulating different functions into methods , You can use its functions directly by calling methods , There is no need to consider the specific function implementation details . */
public class Utility {
private static Scanner scanner = new Scanner(System.in);
/** For interface menu selection . This method reads the keyboard , If the user types ’1’-’4’ Any character in , Then the method returns . The return value is the character that the user typed . */
public static char readMenuSelection() {
char c;
for (; ; ) {
String str = readKeyBoard(1);
c = str.charAt(0);
if (c != '1' && c != '2' && c != '3' && c != '4') {
System.out.print(" Wrong choice , Please re-enter :");
} else break;
}
return c;
}
/** Input for income and expense amounts . This method reads a number from the keyboard that does not exceed 4 An integer of bit length , And take it as the return value of the method . */
public static int readNumber() {
int n;
for (; ; ) {
String str = readKeyBoard(4);
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print(" Wrong number input , Please re-enter :");
}
}
return n;
}
/** Input for income and expense statements . This method reads a number from the keyboard that does not exceed 8 Bit length string , And take it as the return value of the method . */
public static String readString() {
String str = readKeyBoard(8);
return str;
}
/** Input to confirm selection . This method reads... From the keyboard ‘Y’ or ’N’, And take it as the return value of the method . */
public static char readConfirmSelection() {
char c;
for (; ; ) {
String str = readKeyBoard(1).toUpperCase();
c = str.charAt(0);
if (c == 'Y' || c == 'N') {
break;
} else {
System.out.print(" Wrong choice , Please re-enter :");
}
}
return c;
}
private static String readKeyBoard(int limit) {
String line = "";
while (scanner.hasNext()) {
line = scanner.nextLine();
if (line.length() < 1 || line.length() > limit) {
System.out.print(" Input length ( No more than " + limit + ") error , Please re-enter :");
continue;
}
break;
}
return line;
}
}
main interface
package project;
import javax.sound.midi.Soundbank;
public class FamilyAccount {
public static void main(String[] args) {
boolean isFlag = true;
String details = "";
int balance = 10000;
while(isFlag)
{
System.out.println("------------- Household income and expenditure bookkeeping soft -------------\n");
System.out.println(" 1. Income and expenditure details ");
System.out.println(" 2. Registered income ");
System.out.println(" 3. Register expenses ");
System.out.println(" 4. refund Out \n");
System.out.println(" Please select (1-4): ");
// Get user's choice :1-4
char selection = Utility.readMenuSelection();
switch(selection)
{
case '1':
System.out.println("------------- Current revenue and expenditure details record ------------");
System.out.println(" Income and expenditure \t Account amount \t\t Amount of revenue and expenditure \t\t say bright ");
System.out.println(details);
System.out.println("----------------------------------------");
break;
case '2':
System.out.println(" The amount of income this time :");
int addMoney = Utility.readNumber();
System.out.println(" This income statement :");
String addInfo = Utility.readString();
balance += addMoney;
details += " income \t" + balance + "\t\t" + addMoney + "\t\t" + addInfo + "\n";
System.out.println("-------------- Registration completed ---------------\n");
break;
case '3':
System.out.println(" The amount of this expenditure is :");
int minusMoney = Utility.readNumber();
System.out.println(" This expenditure statement :");
String minusInfo = Utility.readString();
if(balance >= minusMoney)
{
balance -= minusMoney;
details += " spending \t" + balance + "\t\t" + minusInfo + "\t\t" + minusInfo + "\n";
}
else
{
System.out.println(" The expenditure exceeds the account limit , Failure to pay ");
}
break;
case '4':
System.out.println(" Confirm whether to exit (Y/N):");
char isExit = Utility.readConfirmSelection();
if(isExit == 'Y')
{
isFlag = false;
}
break;
}
}
}
}
4. Records of basic funds and income and expenditure details
- The record of basic gold can be used int Variable implementation of type int balance = 10000
- Revenue and expenditure detail records can use String Type to implement , Its initial value is null
- When registering income and expenditure , Compare the amount of revenue and expenditure with balance Add or subtract , Revenue and expenditure records are directly linked to details Just behind
5. Implementation of keyboard access
- The project provides Utility.java class , It can be used to conveniently realize keyboard access
- This class provides the following static methods :
- public static char readMenuSelection() : For interface menu selection . This method reads the keyboard , If the user types ’1’-’4’ Any character in , Then the method returns . The return value is the character that the user typed .
- public static int readNumber() : Input for income and expense amounts . This method reads a number from the keyboard that does not exceed 4 An integer of bit length , And take it as the return value of the method .
- public static String readString() : Input for income and expense statements . This method reads a number from the keyboard that does not exceed 8 Bit length string , And take it as the return value of the method .
- public static char readConfirmSelection() : Input to confirm selection . This method reads... From the keyboard ‘Y’ or ’N’, And take it as the return value of the method .
边栏推荐
- BibTex中参考文献种类
- Detailed introduction to the big changes of Xcode 14
- 【Kubernetes系列】Kubernetes 上安装 KubeSphere
- Xcode 14之大变化详细介绍
- 两年前美国芯片扭捏着不卖芯片,如今芯片堆积如山祈求中国帮忙
- 大学阶段总结
- NLP literature reading summary
- What are the work contents of operation and maintenance engineers? Can you list it in detail?
- The number of patent applications in China has again surpassed that of the United States and Japan, ranking first in the world for 11 consecutive years
- Technical experts from large factories: common thinking models in architecture design
猜你喜欢
Master-slave replication principle of MySQL database
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
Go learning notes - constants
Industrial computer anti-virus
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
Status of the thread
Data double write consistency between redis and MySQL
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas
随机推荐
Distributed transaction management DTM: the little helper behind "buy buy buy"
Rhcsa the next day
Node connection MySQL access denied for user 'root' @ 'localhost' (using password: yes
Implementation of ZABBIX agent active mode
[Valentine's day] - you can change your love and write down your lover's name
【FreeRTOS】FreeRTOS學習筆記(7)— 手寫FreeRTOS雙向鏈錶/源碼分析
JVM -- class loading process and runtime data area
【森城市】GIS数据漫谈(一)
tornado之目录
【Kubernetes系列】Kubernetes 上安装 KubeSphere
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
2022-021rts: from the second half of the year
Blog stop statement
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
System architecture design of circle of friends
Flink memory model, network buffer, memory tuning, troubleshooting
This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
Chapter 1 programming problems
Zephyr 学习笔记1,threads
Would you like to go? Go! Don't hesitate if you like it