Java开发一个家庭收支记账软件2.0

income类

/**
 * 
 */
package com.gem.demo.home;

/**
 *
 * Description:
 *
 * @author HadwinLing
 *
 * @date 2020年1月15日下午4:27:40
 *
 * @version 0.0.1 
 *
 */
public class income {
	static int all;
	private int income;
	private String incomeDetail;
	income(){
		all=0;
		income =0;
		incomeDetail="";
		
	}
	income(int all,int income,String incomeDetail){
		this.all = all;
		this.income =income;
		this.incomeDetail = incomeDetail;
	}
	public static int getAll() {
		return all;
	}
	public void setAll(int all,int income,int expend) {
		this.all = all+income-expend;
	}
	public int getIncome() {
		return income;
	}
	public void setIncome(int income) {
		this.income = income;
	}
	public String getIncomeDetail() {
		return incomeDetail;
	}
	public void setIncomeDetail(String incomeDetail) {
		this.incomeDetail = incomeDetail;
	}
	
}

expend类

/**
 * 
 */
package com.gem.demo.home;

/**
 *
 * Description:
 *
 * @author HadwinLing
 *
 * @date 2020年1月15日下午4:27:50
 *
 * @version 0.0.1 
 *
 */
public class expend {
	static int all;
	private int expend;
	private String expendDetail;
	expend(){
		all=0;
		expend =0;
		expendDetail="";
		
	}
	expend(int all,int expend,String expendDetail){
		this.all = all;
		this.expend =expend;
		this.expendDetail = expendDetail;
	}
	public static int getAll() {
		return all;
	}
	public void setAll(int all,int income,int expend) {
		this.all = all+income-expend;
	}
	public int getExpend() {
		return expend;
	}
	public void setExpend(int expend) {
		this.expend = expend;
	}
	public String getExpendDetail() {
		return expendDetail;
	}
	public void setExpendDetail(String expendDetail) {
		this.expendDetail = expendDetail;
	}

}

incomeAndExpand类

/**
 * 
 */
package com.gem.demo.home;

import java.util.Scanner;

/**
 *
 * Description:
 *
 * @author HadwinLing
 *
 * @date 2020年1月15日下午3:57:52
 *
 * @version 0.0.1 
 *
 */
public class incomeAndExpend {
	static income[] incomes  = new income[10];
	static expend[] expends  = new expend[10];
	static int size =0 ;
	static int all = 0;
	static Scanner input = new Scanner(System.in);
	
	
	
	public static void setIncomeInfo() {
		size++;
		System.out.print("本次收入金额为:");
		int income = input.nextInt();
		System.out.print("本次收入说明为:");
		String incomeDetail = input.next();
		income in = new income();
		in.setIncome(income);
		in.setIncomeDetail(incomeDetail);
//		for(int i=0;i<size;i++) {
//			incomes[i-] = in;
//		}
		incomes[size-1] =in;
	}
	public static void setExpendInfo() {
		size++;
		System.out.print("支出金额为:");
		int expend = input.nextInt();
		System.out.print("本次支出说明为:");
		String expendDetail = input.next();
		expend ex  = new expend();
		ex.setExpend(expend);
		ex.setExpendDetail(expendDetail);
//		for(int i=0;i<size;i++) {
//			expends[i] = ex;
//			}
		expends[size-1]=ex;
	}
	

	public static void print() {
		System.out.println("-----------------当前收支明细记录-----------------");
		System.out.println("收支 "+"\t"+"账户金额" +"\t"+"收支金额 "+"\t"+"说  明");
		for(int i=0;i<size;i++) {
			if(incomes[i]!=null) {
				all =all+incomes[i].getIncome();
				System.out.println("收入 \t"+all+"\t"+incomes[i].getIncome()+"\t"+incomes[i].getIncomeDetail());
			}else if(expends[i]!=null) {
				all =all-expends[i].getExpend();
				System.out.print("支出 \t"+all+"\t"+expends[i].getExpend()+"\t"+expends[i].getExpendDetail());
			}else {
				continue;
			}
		}
	}
	
}

incomeAndExpendTest 类

/**
 * 
 */
package com.gem.demo.home;

import java.util.Scanner;

import com.gem.demo.day05_practice.Home;

/**
 *
 * Description:
 *
 * @author HadwinLing
 *
 * @date 2020年1月15日下午3:58:14
 *
 * @version 0.0.1 
 *
 */
public class incomeAndExpendTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("-----------------家庭收支记账软件----------------- ");
		System.out.println("1:收支明细");
		System.out.println("2:登记收入");
		System.out.println("3:登记支出");
		System.out.println("4:退出");
		Scanner input = new Scanner(System.in);
		boolean flag =true;
		incomeAndExpend h = new incomeAndExpend();
		while(flag) {
			System.out.print("请选择(1~4)");
			int num = input .nextInt();
			switch(num) {
				case 1:
					incomeAndExpend.print();
					break;
				case 2:
					incomeAndExpend.setIncomeInfo();
					break;
				case 3:
					incomeAndExpend.setExpendInfo();
					break;
				case 4:
					flag = false;
					break;
				default:
						System.out.println("输入有误");
				}
			System.out.println();
		}

	}

}

2.0还有个小bug,就是我这里设置的是10个长度,没有处理数组长度溢出,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值