public abstract class Shui { protected double shui; public Shui(double shui) { this.shui = shui; }; public abstract double getTax(); } class Salary extends Shui{ public Salary(double shui) { super(shui); } public double getTax() { if(this.shui <= 5000) { return 0; } else { return(this.shui - 5000) * 0.2; } } } class GaoFei extends Shui{ public GaoFei(double shui) { super(shui); } public double getTax() { return this.shui * 0.1; } } class Text{ public static void main(String[] args) { Shui[] shui = new Shui[] {new Salary(6000),new GaoFei(8000)}; double m = 0; for (Shui sh:shui) { m += sh.getTax(); } System.out.print(m); } }
Sign in to make a reply
就是想卖萌