需求:
1.可以简单地核对账号和密码;
2.给定一个本金,可以实现简单的收支计算;
3.可以查询收支明细。
代码模块:
package 基础语法;
//家庭收入支出明细
import java.util.Scanner;
public class Demo5 {
public static void main(String[] args) {
flag1:
while (true) {
System.out.println("请输入账号");
Scanner scanner = new Scanner(System.in);
int Account = scanner.nextInt();
if (Account != 1111) {
System.out.println("账号错误,请重新输入");
continue flag1;
} else {
System.out.println("请输入密码");
int passward = scanner.nextInt();
if (passward != 2222) {
System.out.println("密码错误");
continue flag1;
} else {
flag:
while (true) {
System.out.println("----------家庭收支记账软件----------");
System.out.println("1.收支明细");
System.out.println("2.登记支出");
System.out.println("3.登记收入");
System.out.println("4.查看余额");
System.out.println("5.退出");
System.out.println("请选择(1-5):");
int money = 10000;
Scanner sc = new Scanner(System.in);
String arr[][] = new String[1000][4];
int count = 0;
boolean flag2 = true;
while (flag2) {
int a = sc.nextInt();
if (a == 2) {
System.out.println("请输入支出金额");
int out = sc.nextInt();
System.out.println("请输入支出明细");
String s2 = sc.next();
arr[count][0] = "收入";
money -= out;//总余额等于基础的加收入的
arr[count][1] = String.valueOf(money);//直接把sumNum和num都转换成字符串类型
arr[count][2] = String.valueOf(out);
arr[count][3] = s2;
System.out.println("---请继续执行---");
count++;
} else if (a == 3) {
System.out.println("请输入收入金额");
int in = sc.nextInt();
System.out.println("请输入收入明细");
String s1 = sc.next();
arr[count][0] = "收入";
money -= in;//总余额等于基础的加收入的
arr[count][1] = String.valueOf(money);//直接把sumNum和num都转换成字符串类型
arr[count][2] = String.valueOf(in);
arr[count][3] = s1;
System.out.println("---请继续执行---");
count++;
} else if (a == 1) {
System.out.println("收支 账户总金额 收支金额 说 明");
for (int i = 0; i < arr.length; i++) {//循环打印 输入的数据
if (arr[i][0] != null) {
System.out.println(arr[i][0] + " " + arr[i][1] + " " + arr[i][2] + " " + arr[i][3]);
}
}
System.out.println("---请继续执行---");
} else if (a == 4) {
System.out.println("余额为:" + money);
} else if (a == 5) {
System.out.println("-----重新登录软件请按1-----");
System.out.println("-----退出本系统请按2-----");
int b = sc.nextInt();
if (b == 1) {
break flag;
} else {
break flag1;
}
} else {
System.out.println("指令错误,请重新操作");
flag2 = false;
}
}
}
}
}
}
}
}
运行结果演示: