其他分享
首页 > 其他分享> > 家庭收支记账软件

家庭收支记账软件

作者:互联网

效果:

————————家庭收支记账————————

						1 收支明细
						2 登记收入
						3 登记支出
						4 退       出

						请选择<1-4>:

——————当前收支明细记录————————
收支 账户余额 收支金额 说明

import java.util.Scanner;
public class Utility{
	private static Scanner scanner = new Scanner(System.in);
	
	public static char readMenuSelection(){
		char c;
		for(; ; ){
			String str = readKeyBoard(1);
			c = str.charAt(0);
			if(c!='1'&&c!='2'&&c!='3'&&c!='4'){
				System.out.print("选择错误,请重新输入:");
			}else break;
		}
		return c;
	}
	
	public static int readNumber(){
		int n;
		for(; ; ){
			String str = readKeyBoard(4);//4字节
			try{
				n = Integer.parseInt(str);
				break;
			}catch(NumberFormatException e){
				System.out.print("数字输入错误,请重新输入:")
			}	
		}
		return n;
	}
	
	public static String readString(){
		String str = readKeyBoard(8);
		return str;
	}
	
	public static char readConfirmSelection(){
		char c;
		for(; ; ){
			String str = readKeyBoard(1).toUpperCase();
			c = str.charAt(0);
			if(c=='Y'||c=='N'){
				break;
			}else{
				System.out.print("选择错误,请重新输入:")
			}
		}
		return c;
	}
}
import java.util.Scanner;
class FamilyAccount{
	public static void main(String[] args){
		boolean isFlag = true;
		String details = "收支\t账户余额\t收支金额\t说  明\n";
		int balance = 10000;//总额
		while(isFlag){
			System.out.println(“----------家庭收支记账----------”);
			System.out.println(“           1 收支明细”);
			System.out.println(“           2 登记收入”);
			System.out.println(“           3 登记支出”);
			System.out.println(“           4 退    出”);
			System.out.print(“请选择<1-4>:”);
			char selection = Utility.readMenuSelection();//选项方法
			switch(seclection){
				case '1':
					System.out.println(“----------当前收支明细记录----------”);
					System.out.println(details);
					System.out.println(“----------”);
					break;
				case '2':
					System.out.print(“本次收入金额:”);
					int money  = Utility.readNumber();
					System.out.print(“本次收入说明:”);
					String info = Utility.readString();
					balance += money;
					details += ("收入\t"+balance+"\t"+money+"\t"+info+"\n)";
					System.out.println(“-------登记完成------”);
					break;
				case '3':
					System.out.print(“本次支出金额:”);
					int money1  = Utility.readNumber();
					System.out.print(“本次支出说明:”);
					String info1 = Utility.readString();
					if(balance>=money){
						balance -= money;
						details += ("支出\t"+balance+"\t"+money1+"\t"+info1+"\n");
					}else{
						System.out.println(“钱不够”);
					}
					System.out.println(“-------登记完成------”);
					break;
				case '4':
					System.out.print(“你确定要退出吗?(Y/N):”);
					char isExit = Utility.readConfirmSelection();
					if(isExit=='Y'){
						isFlag = false;
					}
			}
			
		}
}

标签:String,System,收支,print,记账,println,软件,out
来源: https://blog.csdn.net/qq_41571545/article/details/120795405