Discuss / Java / 20%和20%的税率 交税2900 对吗老铁们

20%和20%的税率 交税2900 对吗老铁们

Topic source
public class Main {

	public static void main(String[] args) {
		// TODO: 用抽象类给一个有工资收入和稿费收入的小伙伴算税:
		Income[] incomes = new Income[] { new SalaryIncome(7500), new RoyaltyIncome(12000) };
		double total = 0;
		// TODO:
		for (Income income:incomes) {
			total+= income.getTax();
		}
		System.out.println(total);
	}
}
abstract class Income{
	protected double income;
	public  Income(double income) {
		this.income = income;
	}
	public abstract double getTax();
}
class SalaryIncome extends Income{
	public SalaryIncome(double income) {
		super(income);
	}
	@Override
	public  double getTax() {
		if (this.income <= 5000) {
			return 0;
		}
		return (this.income-5000)*0.2;
	}
}
class RoyaltyIncome extends Income{
	public RoyaltyIncome(double income) {
		super(income);
	}
	@Override
	public double getTax() {
		return this.income*0.2;
	}	
}

  • 1

Reply