package day3;
import java.util.Scanner;
public class demo1 {
/*
设计家庭记账程序(参考图片)
*/
public static void main(String[] args) {
/*
死循环两种方式:
for(;;){}
while(true){}
*/
double money = 0;
String incomInfo = "金额 说明 余额\n";
String outInfo = "金额 说明 余额\n";
outer: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 scanner = new Scanner(System.in);
int inStr = scanner.nextInt();
switch (inStr) {
case 1: {
System.out.println("输入要存入的钱数:");
double incom = scanner.nextDouble();
System.out.println("输入收入说明: ");
String str = scanner.next();
money = money + incom;
System.out.println("账户余额:"+money);
incomInfo = "收入:"+ incom +"收入说明:" + str + "账户余额:"+money+"\n";
break;
}
case 2: {
System.out.println("输入支出的钱数:");
double out = scanner.nextDouble();
System.out.println("输入支出说明:");
String str = scanner.next();
money -=out ;
System.out.println("账户余额:"+money);
outInfo ="支出:"+out + "支出说明:"+out+ "账户余额:" + money+"\n";
break;
}
case 3: {
/*
如何能够输出所有收入、支出记录信息,不覆盖???
*/
System.out.println("-----收支明细-----\n");
System.out.println(incomInfo);
System.out.println(outInfo);
break;
}
case 4: {
break outer;
}
default:
System.out.println("无效输入!");
}
}
}
}
Java语言设计家庭记账程序
最新推荐文章于 2023-08-25 11:48:21 发布