其他分享
首页 > 其他分享> > Switch问题

Switch问题

作者:互联网

package com.company;

public class Main {
public static void main(String[] args) {
Income[] incomes = new Income[]{
new Income(3000),
new Salary(7500),
new State(15000)
};
System.out.println(totalTax(incomes));
}

public static double totalTax(Income... incomes) {
double total = 0;
for (Income income : incomes) {
total = total + income.getTax();
}
return total;
}
}
class Income{
protected double income;

public Income(double income){
this.income=income;
}
public double getTax(){
return income*0.1;//税率
}
}
class Salary extends Income{
public Salary(double income){
super(income);
}
@Override
public double getTax(){
if(income<=5000)
return 0;
return (income-5000)*0.2;
}
}

class State extends Income{
public State(double income){
super(income);
}
@Override
public double getTax(){
return 0;
}
}
输出:123
Switch问题。待解决。

标签:return,double,income,问题,Switch,Income,total,public
来源: https://www.cnblogs.com/yinsan/p/15558057.html