算完了是1136.0,另外不知道为啥乱码
public class Main {
public static void main(String[] args) {
// TODO: 缁欎竴涓湁宸ヨ祫鏀跺叆鍜岀璐规敹鍏ョ殑灏忎紮浼寸畻绋�:
Income[] incomes = new Income[] { new Income(3000), new SalaryIncome(7500), new RoyaltyIncome(12000) };
double total = 0;
for (Income s : incomes) {
total = total + s.getTax();
}
// TODO:
System.out.println(total);
class Income {
protected double income;
public Income(double income) {
this.income = income;
public double getTax() {
return income * 0.1; // 绋庣巼10%
class SalaryIncome extends Income {
public SalaryIncome(double income) {
super(income);
@Override
if (income <= 5000) {
return 0;
return (income - 5000) * 0.2;
class RoyaltyIncome extends Income {
public RoyaltyIncome(double income) {
if (income <= 4000) {
return (this.income - 800) * 0.14;
return this.income * 0.2 * 0.14;
// TODO
Sign in to make a reply
银发的index
算完了是1136.0,另外不知道为啥乱码
public class Main {
public static void main(String[] args) {
// TODO: 缁欎竴涓湁宸ヨ祫鏀跺叆鍜岀璐规敹鍏ョ殑灏忎紮浼寸畻绋�:
Income[] incomes = new Income[] { new Income(3000), new SalaryIncome(7500), new RoyaltyIncome(12000) };
double total = 0;
for (Income s : incomes) {
total = total + s.getTax();
}
// TODO:
System.out.println(total);
}
}
class Income {
protected double income;
public Income(double income) {
this.income = income;
}
public double getTax() {
return income * 0.1; // 绋庣巼10%
}
}
class SalaryIncome extends Income {
public SalaryIncome(double income) {
super(income);
}
@Override
public double getTax() {
if (income <= 5000) {
return 0;
}
return (income - 5000) * 0.2;
}
}
class RoyaltyIncome extends Income {
public RoyaltyIncome(double income) {
super(income);
}
@Override
public double getTax() {
if (income <= 4000) {
return (this.income - 800) * 0.14;
}
return this.income * 0.2 * 0.14;
}
// TODO
}