目录
1.该项目所涉及的主要知识点
2.项目要实现的功能
3.使用的工具(eclipse)
4.代码部分
1.该项目所涉及的主要知识点
①变量的定义
②数据类型的使用
③循环语句(for循环,while循环)
2.项目要实现的功能
①模拟文本界面的《家庭收支管理》
②能够记录家庭的收入,支出,并能打印收支明细表
3.使用的工具(eclipse)
下载地址:Eclipse Downloads | The Eclipse Foundation

目录
1.该项目所涉及的主要知识点
2.项目要实现的功能
3.使用的工具(eclipse)
4.代码部分
①变量的定义
②数据类型的使用
③循环语句(for循环,while循环)
①模拟文本界面的《家庭收支管理》
②能够记录家庭的收入,支出,并能打印收支明细表
下载地址:Eclipse Downloads | The Eclipse Foundation
package com.family.bookkeeping.contact;
import java.util.Scanner;
public class Family_Bookkeeping
{
public static void main(String[] args)
{
String content = "收支t账户金额t收入金额t说 明n";
int money = 10000; //设置初始账户的余额
boolean bun = true;
while (bun)
{
System.out.println("----------家庭收支记账软件----------");
System.out.println(" 1.收支明细 ");
System.out.println(" 2.登记收入 ");
System.out.println(" 3.登记支出 ");
System.out.println(" 4.退 出 ");
boolean button = true;
int number = 0;
int money1 = 0,money2 = 0;
Scanner sc = new Scanner(System.in);
while (button) //确保输入的数字无误
{
System.out.print(" 请输入: ");
number = sc.nextInt();
if (number != 1 && number != 2 && number != 3 && number != 4) {
System.out.println("抱歉您输入的数字有误请重新输入:");
} else {
button = false; //退出循环
}
}
switch (number)
{
case 1 ->
{
System.out.println("-------------当前收支明细记录--------------");
System.out.print(content);
System.out.println("----------------------------------------n");
break;
}
case 2 ->
{
System.out.print("本次收入金额:");
money1 = sc.nextInt();
System.out.println("本次收入说明:");
String info = sc.next();
money += money1;
content += ("收入t" + money + "t" + "+" + money1 + "t" + info + "n"); //更新内容
System.out.println("------------登记完成---------------------n");
break;
}
case 3 ->
{
System.out.print("本次支出金额:");
money2 = sc.nextInt();
System.out.print("本次支出说明:");
String sn = sc.next();
if(money2 > money)
{
System.out.println("余额不足n");
}
else
{
money -= money2;
content += ("支出t" + money + "t" + "-" + money2 + "t" + sn + "n"); //更新内容
System.out.println("------------登记完成---------------------n");
}
break;
}
case 4 ->
{
bun = false;
}
}
}
}
}