小鲨鱼记账系统
package com.msb.test01;
import java.util.Scanner;
public class Test01 {
public static void main(String[] args) {
String detail01 = "";
int balance = 0;
while (true) {
System.out.println("------欢迎使用小鲨鱼记账系统------");
System.out.println("1.收支明细");
System.out.println("2.登记收入");
System.out.println("3.登记支出");
System.out.println("4.退出");
System.out.println("请输入你要选择的功能");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
while(choice!=1&&choice!=2&&choice!=3&&choice!=4)
{
System.out.println("对不起,你录入的功能错误,请重新录入");
int newChoice = sc.nextInt();
choice = newChoice;
}
switch (choice) {
case 1:
System.out.println("记账系统》》》收支明细");
// System.out.println(detail01);
// String s = detail01.substring(0,detail01.length()-1);
if(detail01!="")
{
System.out.println(detail01.substring(0,detail01.length()-1));
}
else
{
System.out.print(detail01);
}
break;
case 2:
System.out.println("记账系统》》》登记收入");
System.out.println("请录入收入金额:");
int income = sc.nextInt();
System.out.println("请录入收入说明:");
String incomeDetail = sc.next();
balance += income;
detail01 = detail01+"收入:"+income+",收入说明:"+incomeDetail+",账户余额:"+balance+"\n";
break;
case 3:
System.out.println("记账系统》》》登记支出");
System.out.println("请录入支出金额:");
int expend = sc.nextInt();
System.out.println("请录入支出说明:");
String expendDetail = sc.next();
balance -=expend;
detail01 = detail01+"支出:"+expend+",支出说明:"+expendDetail+",账户余额:"+balance+"\n";
break;
case 4:
System.out.println("记账系统》》》退出");
System.out.println("确定要退出嘛Y/N");
String isExit = sc.next();
switch(isExit)
{
case "Y":
System.out.println("系统退出,欢迎你下次继续使用");
return;
}
}
}
}
}
效果图: