某公司的雇员分为以下若干类: Employee:这是所有员工总的父类.属性:员工的姓名,员工的生日月份。 方法:getSalary(intmonth)

某公司的雇员分为以下若干类:
    Employee:这是所有员工总的父类,
        属性:
            员工的姓名,员工的生日月份。
        方法:getSalary(intmonth)
            根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。

    SalariedEmployee:
        Employee 的子类,拿固定工资的员工。
        属性:月薪

    HourlyEmployee:
        Employee 的子类, 按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。
        属性:每小时的工资、每月工作的小时数

    SalesEmployee:
        Employee 的子类,销售人员,工资由月销售额和提成率决定。
        属性:月销售额、提成率

    BasePlusSalesEmployee:
        SalesEmployee 的子类,有固定底薪的销售人员,工资 由底薪加上销售提成部分。
        属性:底薪。

    根据要求创建 SalariedEmployee 、 HourlyEmployees 、SaleEmployee 和 BasePlusSalesEmployee四个类的对象各一个,
    并计算某个月这四个对象的工资。

    注意:要求把每个类都做成完全封装,不允许非私有化属性。

主方法main:

public class Test {
    public static void main(String[] args) {  //主方法main
        Employee salariedEmployee = new SalariedEmployee("小月",10,5000);
        Employee hourlyEmployee = new HourlyEmployee("小花",10,10,180);
        Employee salesEmployee = new SalesEmployee("小明",6,2000,2);
        Employee basePlusSalesEmployee = new BasePlusSalesEmployee("小艾",5,1000,2,3000);

        int salary = salariedEmployee.getSalary(10);   //是生日的工资
        System.out.println(salariedEmployee.getName()+"的月薪是:" + salary);
        /*int salary = salariedEmployee.getSalary(10);   //不是生日的工资
        System.out.println(salariedEmployee.getName()+"的月薪是:" + salary);*/

        int salary1 = hourlyEmployee.getSalary(10);  //是生日的工资
        System.out.println(hourlyEmployee.getName()+"的月薪是:" + salary1);
        /*int salary1 = hourlyEmployee.getSalary(2);  //不是生日的工资
        System.out.println(hourlyEmployee.getName()+"的月薪是:" + salary1);*/

        int salary2 = salesEmployee.getSalary(6); // 是生日的工资
        System.out.println(salesEmployee.getName()+"的月薪是:" + salary2);
        /*int salary2 = salesEmployee.getSalary(3); // 是生日的工资
        System.out.println(salesEmployee.getName()+"的月薪是:" + salary2);*/

        int salary3 = basePlusSalesEmployee.getSalary(5);//是生日工资
        System.out.println(basePlusSalesEmployee.getName()+"的月薪是:" + salary3);
        /*int salary3 = basePlusSalesEmployee.getSalary(3);//不是生日工资
        System.out.println(basePlusSalesEmployee.getName()+"的月薪是:" + salary3);*/

    }
}

 员工总的父类Employee:

public class Employee {  //这是所有员工总的父类
    private String name;
    private int month;

    public Employee() {
    }

    public Employee(String name, int month) {
        this.name = name;
        this.month = month;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getSalary(int month){   //让子类去重写
        return 0;
    }
}

 

 子类SalariedEmployee:

/*
SalariedEmployee:
		Employee 的子类,拿固定工资的员工。
		属性:月薪
 */
public class SalariedEmployee extends Employee{  //拿固定工资的员工
        private int yueXin;

        public SalariedEmployee(int yueYin) {
            this.yueXin = yueYin;
        }

    public SalariedEmployee(String name, int month, int yueXin) {
        super(name, month);
        this.yueXin = yueXin;
    }

    public int getYueXin() {
            return yueXin;
        }

        public void setYueXin(int yueXin) {
            this.yueXin = yueXin;
        }

    @Override
    public int getSalary(int month) {
        if (month == getMonth()){
            return getYueXin()+100;
        }else {
            return getYueXin();
        }
    }
}

 子类HourlyEmployee:

/*
HourlyEmployee:
		Employee 的子类, 按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。
		属性:每小时的工资、每月工作的小时数
 */
public class HourlyEmployee extends Employee {  //按小时拿工资的员工
    private int meiXiaoShiGongZi;
    private int meiYueGongZuoXiaoShiSshu;

    public HourlyEmployee(int meiXiaoShiGongZi, int meiYueGongZuoXiaoShiSshu) {
        this.meiXiaoShiGongZi = meiXiaoShiGongZi;
        this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;
    }

    public HourlyEmployee(String name, int month, int meiXiaoShiGongZi, int meiYueGongZuoXiaoShiSshu) {
        super(name, month);
        this.meiXiaoShiGongZi = meiXiaoShiGongZi;
        this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;
    }

    public int getMeiXiaoShiGongZi() {
        return meiXiaoShiGongZi;
    }

    public void setMeiXiaoShiGongZi(int meiXiaoShiGongZi) {
        this.meiXiaoShiGongZi = meiXiaoShiGongZi;
    }

    public int getMeiYueGongZuoXiaoShiSshu() {
        return meiYueGongZuoXiaoShiSshu;
    }

    public void setMeiYueGongZuoXiaoShiSshu(int meiYueGongZuoXiaoShiSshu) {
        this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;
    }

    public int getSalary(int month) {
        if (getMeiYueGongZuoXiaoShiSshu() > 160) {
            if (month == getMonth()) {
                double v = (getMeiYueGongZuoXiaoShiSshu() - 160) * (1.5 * getMeiXiaoShiGongZi());
                int i = getMeiXiaoShiGongZi() * 160;
                return (int) (v + i + 100);
            }else {
                double v = (getMeiYueGongZuoXiaoShiSshu() - 160) * (1.5 * getMeiXiaoShiGongZi());
                int i = getMeiXiaoShiGongZi() * 160;
                return (int) (v + i);
            }
        } else {
            if (month == getMonth()) {
                int i = (getMeiXiaoShiGongZi() * getMeiYueGongZuoXiaoShiSshu()) + 100;
                return i;
            } else {
                int i = getMeiXiaoShiGongZi() * getMeiYueGongZuoXiaoShiSshu();
                return i;
            }
        }
    }
}

 子类SalesEmployee:    销售人员

/*
SalesEmployee:
		Employee 的子类,销售人员,工资由月销售额和提成率决定。
		属性:月销售额、提成率
 */
public class SalesEmployee extends Employee {   //销售人员,工资由月销售额和提成率决定
    private int yueXiaoShouE;
    private double tiChengLv;

    public SalesEmployee(int yueXiaoShouE, double tiChengLv) {
        this.yueXiaoShouE = yueXiaoShouE;
        this.tiChengLv = tiChengLv;
    }

    public SalesEmployee(String name, int month, int yueXiaoShouE, double tiChengLv) {
        super(name, month);
        this.yueXiaoShouE = yueXiaoShouE;
        this.tiChengLv = tiChengLv;
    }

    public int getYueXiaoShouE() {
        return yueXiaoShouE;
    }

    public void setYueXiaoShouE(int yueXiaoShouE) {
        this.yueXiaoShouE = yueXiaoShouE;
    }

    public double getTiChengLv() {
        return tiChengLv;
    }

    public void setTiChengLv(double tiChengLv) {
        this.tiChengLv = tiChengLv;
    }

    @Override
    public int getSalary(int month) {

        if (month == getMonth()) {
            double v = (getYueXiaoShouE() * getTiChengLv());
            int v1 = (int) v + 100;
            return v1;
        } else {
            double v = (getYueXiaoShouE() * getTiChengLv());
            return (int) v;
        }

    }
}

 子类:BasePlusSalesEmployee 

/*
BasePlusSalesEmployee:
		SalesEmployee 的子类,有固定底薪的销售人员,工资 由底薪加上销售提成部分。
		属性:底薪。
 */
public class BasePlusSalesEmployee extends SalesEmployee{  //有固定底薪的销售人员
    private int diXin;

    public BasePlusSalesEmployee(int yueXiaoShouE, double tiChengLv, int diXin) {
        super(yueXiaoShouE, tiChengLv);
        this.diXin = diXin;
    }

    public BasePlusSalesEmployee(String name, int month, int yueXiaoShouE, double tiChengLv, int diXin) {
        super(name, month, yueXiaoShouE, tiChengLv);
        this.diXin = diXin;
    }

    public int getDiXin() {
        return diXin;
    }

    public void setDiXin(int diXin) {
        this.diXin = diXin;
    }

    @Override
    public int getSalary(int month) {
        if (month == getMonth()){
            double v = getDiXin() + (getYueXiaoShouE() * getTiChengLv());
            return (int) (v+100);
        }else {
            double v = getDiXin() + (getYueXiaoShouE() * getTiChengLv());
            return (int) v;
        }
    }
}

  • 25
    点赞
  • 162
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数组章节作业 1、将一个数组中的元素倒排过来,不能新开一个数组的临时存储空 间,只能在原数组上改。 2、写一个类用来模拟栈这种数据结构,要求底层 使用数组存储数据, 并给出相应的进栈和出栈的方法。MyStack int arr[]; int count;//栈中元素个数 public MyStack(int n){ arr = new int[n]; } boolean push(int num){ if(count==arr.length){} arr[count++]=num; } int pop(){ if(count==0){ return -1;} return arr[--count]; } 3、实现在一个数组指定位置添加元素和删除元素的功能。 1、数组容量问题? 2、添加元素前后数组中元素的变化 3、删除元素前后数组中元素的变化 面向对象章节作业 1,写一个类,名为Animal,该类有两个私有属性, name(代表动物的名字),和legs(代表动物的腿的条 数)。并提供个两构造方法,一个无参,默认给name 赋值为AAA,给legs赋值为4;另一个需要两个参数, 分别用这两个参数给私有属性赋值。该类还有两个重载的move()方法,其中一个无参,在屏幕上输出一行文字: XXX Moving!!(XXX为该动物的名字);另一个需要一个int参数n,在屏幕上输出n次 XXX Moving!! 2,写一个类Person,包含以下属性:String name; int age; boolean gender; Person partner。 为Person类写一个marry(Person p)方法,代表当前 对象和p结婚,如若可以结婚,则输出恭贺信息, 否则输出不能结婚原因。要求在另外一个类中写一 个主方法,来测试以上程序。(下列情况不能结婚: 结婚年龄,男<24,女<22;3,某一方已婚) 3,写一个类,名为Animal,该类有两个私有属性,name(代表动物的名字),和legs(代表动物的腿的条数);要求为两个私有属性提供public 的访问方法。并提个两构造方法,一个无参,默认给name赋值为AAA,给legs赋值为4;另一个需要两个参数,分别用这两个参数给私有属性赋值。要求在第一个构造方法中调用第二个构造方法。该类还有两个重载的move()方法,其中一个无参,在屏幕上输出一行文字: XXX Moving!!(XXX为该动物的名字);另一个需要一个int参数n,在屏幕上输出n次 XXX Moving!! 4,写一个类Fish,继承自Animal类,并提供一个构造方法,该构造方法需要一个参数name,并给legs赋默认值0;该类还要求覆盖Animal类中的无参move()方法,要求输出:XXX Swimming!! 5,写一个类Bird,继承自Animal类,并提供一个构造方法,该构造方法需要一个参数name,并给legs赋默认值2;该类还要求覆盖Animal类中的无参move()方法,要求输出:XXX Flying!! 6,写一个类Zoo,要求分别生成若干个Animal,Fish和Bird。并调用他们的属性方法。 7,写Shape类,要求如下: 1.int类型属性x和y,分别表示图形的中心点坐标 2.无参构造器 3.构造器,对x和y进行初始化 4.draw()方法,输出"Shape draw" 写Circle类,继承Shape类,要求如下 1.double类型属性r,表示圆的半径 2.无参构造器,将r初始化为1.0 3.构造器,对r进行初始化 4.构造器,对x、y、r进行初始化 5.draw()方法,输出"draw in circle"和x,y,r的值 写Rectangle类,继承Shape类,要求如下 1.double类型属性height和width,表示矩形的高和宽 2.无参构造器,将height和width都初始化为1.0 3.构造器,对height和width进行初始化 4.构造器,对x、y、height、width进行初始化 5.draw()方法,输出"draw in rectangle"和x,y,height,width的值 使用ShapeTest类测试以上代码。 8,某公司雇员分为以下若干类Employee这是所有员工父类属性员工姓名,员工生日月份方法getSalary(int month) 根据参数月份来确定工资,如果该月员工生日,则公司会额外奖励100元。 SalariedEmployeeEmployee的子类,拿固定工资的员工属性:月薪 HourlyEmployeeEmployee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。属性:每小时的工资、每月工作的小时数 SalesEmployeeEmployee的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率 BasedPlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。属性:底薪。 写一个程序,把若干各种类型的员工放在一个Employee数组里,写一个函数,打印出某月每个员工的工资数额。注意:要求把每个类都做成完全封装,不允许非私有化属性。 容器类章节作业 1、写MyStack类,实现栈功能。在类中使用ArrayList保存数据。 2、使用TreeSet和Comparator,写TreeSetTest1 要求:对TreeSet中的元素"HashSet"、"ArrayList"、"TreeMap"、"HashMap"、"TreeSet"、"LinkedList"进行升序和倒序排列 3、使用TreeSet和Comparator,写TreeSetTest2 要求:对TreeSet中的元素1,2,3,4,5,6,7,8,9,10进行排列,排序逻辑为奇数在前偶数在后,奇数按照升序排列,偶数按照降序排列 4、使用TreeSet和Comparator,写TreeSetTestInner 要求: 对TreeSet中的元素"HashSet"、"ArrayList"、"TreeMap"、"HashMap"、"TreeSet"、"LinkedList"进行升序和倒序排列 1. 使用匿名内部类实现 2. 使用静态内部类实现
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值