当前位置:网站首页>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 .
边栏推荐
- Finishing (III) - Exercise 2
- The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
- Crawler (III) crawling house prices in Tianjin
- Novel website program source code that can be automatically collected
- Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
- window上用.bat文件启动项目
- 电子协会 C语言 1级 34 、分段函数
- Electronic Association C language level 1 34, piecewise function
- Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
- 大学阶段总结
猜你喜欢
节点基础~节点操作
电脑通过Putty远程连接树莓派
MySQL中的文本處理函數整理,收藏速查
What are the work contents of operation and maintenance engineers? Can you list it in detail?
A real penetration test
【森城市】GIS数据漫谈(一)
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
Deep profile data leakage prevention scheme
Unity opens the explorer from the inspector interface, selects and records the file path
University stage summary
随机推荐
Zephyr Learning note 2, Scheduling
Rhcsa the next day
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
Types of references in BibTex
Node connection MySQL access denied for user 'root' @ 'localhost' (using password: yes
Would you like to go? Go! Don't hesitate if you like it
Zephyr 學習筆記2,Scheduling
University stage summary
It's healthy to drink medicinal wine like this. Are you drinking it right
Paddleocr prompt error: can not import AVX core while this file exists: xxx\paddle\fluid\core_ avx
NLP-文献阅读总结
Redis - detailed explanation of cache avalanche, cache penetration and cache breakdown
Data double write consistency between redis and MySQL
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
Docker install MySQL
Node foundation ~ node operation
Zephyr learning notes 1, threads
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
Experience installing VMware esxi 6.7 under VMware Workstation 16
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and