Shark(鯊魚記賬系統(tǒng))–附源碼
程序員就要多擼代碼,以便在腦海中形成深刻記憶,昨晚試著擼了一個小小的記賬系統(tǒng)邀跃,內(nèi)容很簡單,主要負(fù)責(zé)簡單的記賬,不過沒用到持久層星爪,后續(xù)會做持久層的版本诺核,先看個簡單的把憎瘸。
package com.shayu.note;
import java.util.Scanner;
public class SharkSystem {
double shouru = 0;
double zhichu = 0;
String shouruSM;
String zhichuSM;
double balance;
String details = "";//用來接收所有輸入的內(nèi)容
boolean flag = true;//定義標(biāo)記
public void StartSystem() {//定義方法
// //下面開始循環(huán)
while (flag) {
//開機界面
System.out.println("-----歡迎使用鯊魚記賬系統(tǒng)-----");
System.out.println("1锅风,收支明細(xì)");
System.out.println("2咖驮,登記收入");
System.out.println("3,登記支出");
System.out.println("4,退出系統(tǒng)");
System.out.println("請按照提示選擇你要使用的的功能--");
Scanner scanner = new Scanner(System.in);//判斷用戶輸入是否符合要求
int choice = scanner.nextInt();//選擇
//檢測用戶輸入的數(shù)據(jù)并返回相應(yīng)的請求結(jié)果
while (choice != 1 & choice != 2 & choice != 3 & choice != 4) {
System.out.println("請重新輸入--");
int newchoice = scanner.nextInt();
choice = newchoice;
}
//定義具體的功能模塊//輸入對應(yīng)數(shù)字選擇功能
switch (choice) {
case 1://收支明細(xì)
System.out.println("歡迎使用小鯊魚收支記賬系統(tǒng)》》》");
System.out.println("收支明細(xì)--");
//之后再次獲取用戶輸入的內(nèi)容
//這里打印明細(xì)
if (details != "") {
System.out.println(details.substring(0, details.length() - 1));
} else {
System.out.print(details);
}
break;
case 2://登記收入
System.out.println("請輸入您的收入--");
shouru = scanner.nextDouble();
System.out.println("請輸入收入說明--");
shouruSM = scanner.next();
System.out.println("-登記完成-");
balance += shouru;
details = details + "收入:" + shouru + ",收入說明:" + shouruSM + ",賬戶余額:" + balance + "\n";
break;
case 3://登記支出
System.out.println("請輸入您的支出--");
zhichu = scanner.nextDouble();
System.out.println("請輸入支出說明--");
zhichuSM = scanner.next();
System.out.println("-登記完成-");
balance -= zhichu;
details = details + "支出:" + zhichu + ",支出說明:" + zhichuSM + ",賬戶余額:" + balance + "\n";
break;
case 4://退出系統(tǒng)
System.out.println("記賬系統(tǒng)》》》您確定要退出系統(tǒng)?(Y/N)");
//判斷用戶輸入Y/N
String isExist = scanner.next();
switch (isExist) {
case "Y":
System.out.println("系統(tǒng)已退出好唯,歡迎您下次繼續(xù)使用蜕提!");
System.exsit(1); //1正退出,0異常退出
}
}
scanner.close();
}
}
}
package com.shayu.note;
import java.util.Scanner;
//鯊魚記賬系統(tǒng)
public class Shark {
public static void main(String[] args) {
SharkSystem shark=new SharkSystem();
shark.StartSystem();
}
}