java home billing system

The following is our question this time:

Requirement specification
• Analog implement a text-based interface "family accounting software."
• The software can record household income, expenditure, balance of payments and the ability to print list.
• Project hierarchical menu mode. Main Menu as follows:
----------------- ----------------- household income and expenditure accounting software

1 income and expenditure details
2 registration income
3 registration expenses
4 exit

Select (1-4): _

Statement of needs

• Assume the basic living gold starting families of 10,000 yuan.
• After each registration income (Menu 2), the amount of revenue to be accumulated on the basic rate, and note the
record of this income details for subsequent queries.
• After each registration expenses (menu 3), the amount of expenditure should be the basic deduct, and note the
record this expense statement, so that subsequent queries.
• When the query income and expenditure details (menu 1), will show all the income and expenditure were fine list

Of needs
and processes • "registered income" interface operation is as follows:
----------------- ----------- household income and expenditure accounting software ------
1 income and expenditure details
2 registration income
3 registration expenses
4 exit
select (1-4): 2
The amount of revenue: income 1000 times Description: labor costs _

Requirement specification
interface and operation • "Registration expenses" is as follows:
----------------- ----------- household income and expenditure accounting software ------
1 income and expenditure details
2 registration income
3 registration expenses
4 exit
select (1-4): 3
The amount spent: 800
The expenditure Description: Property expenses _

Requirement specification
shown • "income and expenditure details" interface and operation is as follows:
----------------- ---------- household income and expenditure accounting software -------
1 income and expenditure details
2 registration income
3 registration expenses
4 exit
select (1-4): 1
----------------- record current income and expenditure details -----------------

Demand Description
• "exit" interface and operation are as follows:
----------------- ------------ household income and expenditure accounting software -----
. 1 balance details
2 revenue register
3 expenditure registration
4 exit
select (1-4): 4 confirm exit (Y / N): _

 

Then below two code portions for your choice:
** **. 1
Import java.util.Scanner;

{class ndemo0001 public
public static void main (String [] args) {
int S = 1000;
String Detai = "";
System.out.println ( "-------------- budgets accounting software ----------------- ");
System.out.println (" 1. income and expenditure details ");
System.out.println (" 2. registration income " );
System.out.println ( "registration 3. expenditure");
System.out.println ( "4. exit");
System.out.println ( "select 1-4");


= Key to true Boolean;
the while (Key) {

Scanner Scanner Scanner new new = (the System.in);
int scanner.nextInt A = ();


int A = A1;
IF (A1> = A1. 5 || <= 0) {
the System .out.println ( "input error");

}
the else {

Switch (A1) {

Case 2:
int = scanner.nextInt in ();
String scanner.nextLine Wi = ();
System.out.println ( "The revenue amount: "+ in);
System.out.println (" The income Description: "+ the Wi);
S = S + in;
Detai + =" income \ t "+ s +" \ t \ t "+ in +" \ T \ T "+ Wi +" \ n-";

System.out.println (" -------------------------------- ------------------ ");
System.out.println (" -------------- household income and expenditure accounting software - --------------- ");
System.out.println ("1. income and expenditure details ");
System.out.println (" 2. Registration income ");
System.out.println ( "3. Registration expenditure");
System.out.println ( "4. Exit");
System.out.println ( "Select 1-4");
BREAK;
Case. 3:
int = OUT scanner.nextInt ();
String scanner.nextLine WO = ();
System.out.println ( "The spend:" OUT +);
System.out.println ( "The expenditure Description:" + WO);
S S-OUT =;
Detai + = "spending \ T" + S + "\ T \ T" + OUT + "\ T \ T" + WO + "\ n-";

System.out.println ( "------- --------------------------------------------- ");
System. out.println ( "-------------- household income and expenditure accounting software -----------------");
System.out.println ( "1. income and expenditure details");
System.out.println ( "2. registration revenue");
System.out.println ( "3. registration expenses");
System.out.println ( "4. Exit");
System.out.println ( "Select 1-4");
BREAK;
Case. 1:
System.out.println ( "---------- current income and expenditure details -------------------------");
System .out.println ( "balance \ t account balance \ t \ t \ t payments amount \ t \ t \ t \ t Description \ t");
System.out.println (Detai);

System.out.println ( "-----------------------------------------------") ;
System.out.println ( "household income and expenditure accounting software -------------- -----------------");
System. out.println ( "1. details balance");
System.out.println ( "registration 2. income");
System.out.println ( "registration 3. expenditure");
System.out.println ( ". 4. exit ");
System.out.println (" select 1-4 ");
BREAK;
Case. 4:
System.out.println (" Are you sure to quit (Y / n-): ");
String = Turn scanner.nextLine ( );
IF (Turn == "Y") {
Key = to false;
the System.out.println ( "End");
}
// the else {
// System.out.println ( "-------------- ----------------- household income and expenditure accounting software");
/ / System.out.println ( "1. income and expenditure details");
// System.out.println ( "2. registration revenue");
// System.out.println ( "3. registration expenses");
// System.out.println ( "4. exit");
// System.out.println ( "select 1-4");
//}
// BREAK;
}


}
}


}
}
However, there are some minor problems during the actual running, during the fourth step, error and will not respond, I hope we can help pointing the wrong mistake. . .
So there is a code, using the following method:
Import java.util.Scanner;
/ **
Utility Tools:
different packaging functions as a method, it is possible to use the method by calling the function directly, without consideration of specific function implementation details.
* /
Public class Utility {
Private = new new static Scanner Scanner Scanner (the System.in);
/ **
interface for selecting a menu. The method reads the keyboard, if a user types "1" - any character of '4', then the method returns. The return value is the user types characters.
* /
Public static char readMenuSelection () {
; C char
(;;) for {
String readKeyBoard STR = (. 1);
C = str.charAt (0);
! IF (= C '. 1' && C = '2'! ! && = C '. 3' && C = '. 4') {!
of System.out.print ( "wrong choice, please re-enter:");
} the else BREAK;



/ **
used to enter the amount of income and expenditure. The method for reading from a keyboard not exceed an integer of 4-bit length, and as the return value.
* /
Public static readNumber int () {
int n-;
for (;;) {
String readKeyBoard STR = (. 4);
the try {
n-= the Integer.parseInt (STR);
BREAK;
} the catch (a NumberFormatException E) {
the System.out. print ( "digital input error, please re-enter:");
}
}
return n-;
}
/ **
for revenue and expenditure input description. The method for reading from a keyboard string length is not more than 8, and as the return value.
* /
Public static String readString () {
String readKeyBoard STR = (. 8);
return STR;
}

/ **
for confirming the selected input. The method reads the 'Y' or 'N' from the keyboard, and as the return value.
* /
Public static char readConfirmSelection () {
C char;
for (;;) {
String readKeyBoard STR = (. 1) .toUpperCase ();
C = str.charAt (0);
IF (C == 'the Y' || C == 'N') {
BREAK;
the else {}
of System.out.print ( "wrong choice, please re-enter:");
}
}
return C;
}


Private static String readKeyBoard (int limit) {
String Line = "";

the while (Scanner.hasNext ()) {
Line scanner.nextLine = ();
IF (line.length () <|| line.length. 1 ()> limit) {
of System.out.print ( "input length (no greater than" + limit + ") error, please re-enter:");
Continue;
}
BREAK;
}

Line return;
}
}
The above is a method library
public class try101 {
public static void main (String [] args) {
String DETA = "balance \ t \ t balance \ t \ t balance amount \ t \ t Text \ n" ;

int Danan = 10000;
boolean = Flag to true;
the while (Flag) {
System.out.println ( "--------------- -------- home accounting software ---- ");
System.out.println (" 1. income and expenditure details ");
System.out.println (" 2. income amount ");
System.out.println (" 3. expenditure amount ");
System.out.println ( "4. exit");
System.out.println ( "Please select the service items:");
char Utility.readMenuSelection A = ();
IF (A == '. 1') {
the System.out .println ( "-------------- income and expenditure details ------------------");
System.out.println (DETA) ;
System.out.println();
System.out.println ( "Please select the service items:");

}
IF (A == '2') {
System.out.println ( "the amount of revenue");
int = Utility.readNumber in ();
the System.out .println ( "income Description");
String the Wi = Utility.readString ();

Danan = Danan + in;
DETA + = "income \ t \ t" + danan + "\ t \ t" + in + "\ t \ t" + + Wi "\ n-";
System.out.println ( "Please select the service items:");

}
IF (A == '. 3') {
System.out.println ( "spend");
int OUT = Utility.readNumber ();
System.out.println ( "Description expenditure");
String Utility.readString WO = ();
Danan Danan-= OUT;
DETA + = "expense \ t \ t" + danan + "\ t \ t" + out + "\ T \ T" + WO + "\ n-";
the System.out.the println ( "Please select services:");

}
IF (A == '. 4') {
System.out.println ( "Leave");
char of = Utility.readConfirmSelection();
if(of=='Y') {
flag = false;
System.out.println("已退出");
}


}
}
}

}

Guess you like

Origin www.cnblogs.com/weiyang2/p/12669046.html