当前位置:网站首页>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 .
边栏推荐
- With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
- Why does the producer / consumer mode wait () use while instead of if (clear and understandable)
- Electronic Association C language level 1 34, piecewise function
- The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
- socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
- Introduction to rce in attack and defense world
- NLP-文献阅读总结
- Splicing plain text into JSON strings - easy language method
- BibTex中参考文献种类
- MySQL storage engine
猜你喜欢

Pangu open source: multi support and promotion, the wave of chip industry

Zephyr 學習筆記2,Scheduling

Experience installing VMware esxi 6.7 under VMware Workstation 16

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

Unity 从Inspector界面打开资源管理器选择并记录文件路径
![[MySQL transaction]](/img/4f/dbfa1bf999cfcbbe8f3b27bb1e932b.jpg)
[MySQL transaction]

Zephyr 学习笔记1,threads

Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)

节点基础~节点操作

博客停更声明
随机推荐
Node foundation ~ node operation
This article is enough for learning advanced mysql
Routing decorator of tornado project
节点基础~节点操作
MySQL 数据库 - 函数 约束 多表查询 事务
Crawler (III) crawling house prices in Tianjin
window上用.bat文件启动项目
System architecture design of circle of friends
[Valentine's day] - you can change your love and write down your lover's name
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
Chapter 1 programming problems
tornado之目录
Paddleocr prompt error: can not import AVX core while this file exists: xxx\paddle\fluid\core_ avx
MySQL error resolution - error 1261 (01000): row 1 doesn't contain data for all columns
Deep profile data leakage prevention scheme
win10微软拼音输入法输入文字时候下方不出现中文提示
Life planning (flag)
This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
Docker install MySQL
Comparison between applet framework and platform compilation