Discuss / Java / 交作业

交作业

Topic source

康208970

#1 Created at ... [Delete] [Delete and Lock User]

public class Main {
public static double TotalTax(Income... incomes){
double total=0;
for(Income income:incomes){
total+=income.getTax();
}
return total;
}
public static void main(String[] args) {
// TODO: 给一个有工资收入和稿费收入的小伙伴算税:
Income[] incomes = new Income[] { new Income(3000), new SalaryIncome(7500), new RoyaltyIncome(12000) };
// TODO:
System.out.println(TotalTax(incomes));
}
}

**********************************

**********************************

public class Income {
protected double income;
public Income(double income) {
this.income = income;
}
public double getTax() {
return income * 0.1; // 税率10%
}
}

**********************************

public class SalaryIncome extends Income {
public SalaryIncome(double income) {
super(income);
}
@Override
public double getTax() {
if (income <= 5000) {
return 0;
}
return (income - 5000) * 0.2;
}
}

**********************************

public class RoyaltyIncome extends Income{
public RoyaltyIncome(double income){
super(income);
}
// TODO
public double getTax() {
return 0; // 税率10%
}
}


  • 1

Reply