当前位置:网站首页>Day 4 (item 1: household income and expenditure records)
Day 4 (item 1: household income and expenditure records)
2022-07-24 19:18:00 【to be__】
FamilyAccount.java And Utility.java Put it under the same root directory
// The code is as follows :
package project01;
public class FamaillyAccount {
public static void main(String[] arg){
String details = " Income and expenditure \t Amount of account \t Amount of revenue and expenditure \t say bright \n";
int balance = 10000;
boolean loopFlag = true;
do {
System.out.println("----------------- Family income and expenditure accounting software -----------------");
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 ");
System.out.println();
System.out.println(" Please select (1-4): ");
char keyNumber = Utility.readMenuSelection();
switch (keyNumber){
case '1':
System.out.println("----------------- Current revenue and expenditure details record -----------------");
System.out.println(details);
System.out.println("-----------------------------------------------");
break;
case '2':
System.out.println(" The amount of income this time :");
int amount1 = Utility.readNumber();
System.out.println(" This income statement :");
String dec1 = Utility.readString();
System.out.println("------------------- Registration completed --------------------\n");
balance += amount1;
details += " income " + "\t" + balance + "\t\t" + amount1 + "\t\t" + dec1 +"\n";
break;
case '3':
System.out.println(" The amount of this expenditure is :");
int amount2 = Utility.readNumber();
System.out.println(" This expenditure statement :");
String dec2 = Utility.readString();
balance -= amount2;
details += " spending " + "\t" + balance + "\t\t" + amount2 + "\t\t" + dec2 +"\n";
System.out.println("------------------- Registration completed --------------------\n");
break;
case '4':
System.out.println(" Confirm whether to exit Y/N:");
char conf = Utility.readConfirmSelection();
break;
}
}while (loopFlag);
}
}
stay FamilyAccount.java Used in Utility The document code is as follows :
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;
}
}
(b Standing in Silicon Valley java Video learning record )
边栏推荐
- Sequences, time series and prediction in tessorflow quizs on coursera (I)
- Pam4 popular science
- Pay close attention! List of the latest agenda of 2022 open atom open source Summit
- Arrays
- Install SSL Certificate in Litespeed web server
- High speed ASIC packaging trends: integration, SKU and 25g+
- Convolution neural network receptive field calculation Guide
- Interceptors and filters
- Convolutional neural network CNN
- Free and open source website navigation source code collection, sorting and summary - self built personal navigation Homepage
猜你喜欢

High speed ASIC packaging trends: integration, SKU and 25g+

Leetcode652 finding duplicate subtrees

Biopharmaceutical safety, power supply and production guarantee

What are the benefits of knowledge management in enterprises?
![[question 39] special question for Niuke in-depth learning](/img/18/0e182f2c003ff5dd8ed3751c718d73.png)
[question 39] special question for Niuke in-depth learning

PWN learning

This visual analysis library makes it easy for you to play with data science!

多线程与并发编程常见问题(未完待续)

Decision tree_ ID3_ C4.5_ CART

Crazy God redis notes 11
随机推荐
Nacos简介和控制台服务安装
Data model subclassing reference
MySQL1
拦截器和过滤器
Ebpf verifier
[JVM learning 03] class loading and bytecode Technology
Nacos introduction and console service installation
Meshlab&PCL ISS关键点
OpenGL learning (II) opengl rendering pipeline
2022 Hangzhou Electric Multi school first Dragon Slayer (dfs+ state compression)
How does PostgreSQL decide PG's backup strategy
OPENGL学习(三)GLUT二维图像绘制
MySQL hidden version number
MySQL8.0学习记录20 - Trigger
Integer
Sequences, time series and prediction in tessorflow quizs on coursera (II)
PCI express physical layer - electrical part
Tcl/tk file operation
Detailed explanation of the relationship between MySQL tables
Zooinspector Download