第十五周作业

 

 

package homework_15;

public abstract class ColaEmployee {
    protected String m_Name;
    protected int m_Month;
    public ColaEmployee(){}
    public ColaEmployee(String name,int month){
        m_Name=name;
        m_Month=month;
    }
    public double getSalary (int month){
        return 0;
    }
}
package homework_15;

public class SalariedEmployee extends  ColaEmployee {
    private int m_MMoney=100000;
    public SalariedEmployee(){}
    public SalariedEmployee(String name,int month){
        m_Name=name;
        m_Month=month;
    }
    public double getSalary(int month){
        if(month==m_Month){
            return m_MMoney+100;
        }else{
            return m_MMoney;
        }
    }
}
package homework_15;

public class SalesEmployee extends ColaEmployee{
    private double m_Sale=100;
    private double m_Rate=0.1;
    public SalesEmployee(){}
    public SalesEmployee(String name,int month){
        super(name,month);
    }
    public double getSalary(int month){
        if(m_Month==month){
            return m_Sale*m_Rate+100;
        }else{
            return m_Sale*m_Rate;
        }
    }
}
package homework_15;

public class HourlyEmployee extends ColaEmployee{
    private int m_HMoney=1000;
    private int m_Hour;
    public HourlyEmployee(){
    }
    public HourlyEmployee(String name,int month,int hour){
        m_Name=name;
        m_Month=month;
        m_Hour=hour;
    }
    public double getSalary(int month){
        if(month==m_Month&&m_Hour<=160){
            return m_HMoney*m_Hour+100;
        }else if(month==m_Month&&m_Hour>160){
            return (m_HMoney*160)+(m_HMoney*(160-m_Hour))+100;
        }else if(month!=m_Month&&m_Hour>160){
            return (m_HMoney*160)+(m_HMoney*(160-m_Hour));
        }else{
            return m_HMoney*m_Hour;
        }
    }
}
package homework_15;

public class Company {
    public void printCompany(ColaEmployee c,int month){
        System.out.println(c.m_Name+"员工"+month+"月工资为:"+c.getSalary(month));
    }
}
package homework_15;

public class TestCompany {

    public static void main(String[] args) {
         TODO Auto-generated method stub
        ColaEmployee[] c1={
                new SalariedEmployee(张三,6),
                new HourlyEmployee(李四,6,161),
                new SalesEmployee(王五在摸鱼,6)
        };
         Company company = new Company();
         for(int i=0;ic1.length;i++){
             company.printCompany(c1[i], 10);
         }
    }

}

 

 

package homework_15_2;

public class Apple {
    public Apple(){
        System.out.println("苹果");
    }
}
package homework_15_2;

public class Banana {
    public Banana(){
        System.out.println("苹果");
    }
}
package homework_15_2;

public class Gardener {
    public Gardener(){
        System.out.println("园丁");
    }
}
package homework_15_2;

public class Grape {
    public Grape(){
        System.out.println("葡萄");
    }
}
import java.util.Scanner;

public class Tesr {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scanner = new Scanner(System.in);
        String result = scanner.next();
        Object object;
        if (result.equals("苹果")) {
            object = new Apple();
        }
        else if (result.equals("香蕉")) {
            object = new Banana();
        }
        else if (result.equals("葡萄")) {
            object = new Grape();
        }
        else if (result.equals("园丁")) {
            object = new Gardener();
        }
        else {
            System.out.println("请输入正确的指令");
        }
    }

}

posted @ 2021-06-18 18:04  计算机1902佟阳  阅读(27)  评论(0编辑  收藏  举报