第十五周作业
Posted 五谷鸡爪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十五周作业相关的知识,希望对你有一定的参考价值。
public class ColaEmployee { String name; int 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 ColaEmployee(String name, int month) { super(); this.name = name; this.month = month; } public ColaEmployee() { super(); } public double getSalary(int month){ return 0; } }
public class SalariedEmployee extends ColaEmployee { double money; public SalariedEmployee(String name, int month,double money) { super(name, month); this.money=money; // TODO Auto-generated constructor stub } public double getSalary(int month){ if (super.month==month) { return money +100; } else { return money; } } }
public class HourlyEmployee extends ColaEmployee { int hourMoney; int hourSum; public int getHourMoney() { return hourMoney; } public void setHourMoney(int hourMoney) { this.hourMoney = hourMoney; } public int getHourSum() { return hourSum; } public void setHourSum(int hourSum) { this.hourSum = hourSum; } public HourlyEmployee(String name, int month, int hourMoney, int hourSum) { super(name, month); this.hourMoney = hourMoney; this.hourSum = hourSum; } public HourlyEmployee(String name, int month) { super(name, month); } public double getSalary(int month){ if (super.month==month) { if (hourSum>160) { return hourMoney*160+hourMoney*(hourSum-160)*1.5+100; } else { return hourMoney*hourSum+100; } } else { if (hourSum>160) { return hourMoney*160+hourMoney*(hourSum-160)*1.5; } else { return hourMoney*hourSum+100; } } } }
public class SalesEmployee extends ColaEmployee { private int monthSales; private double royaltyRate; public SalesEmployee(String name, int month,int monthSales,double royaltyRate) { super(name, month); this.monthSales = monthSales; this.royaltyRate = royaltyRate; } public double getSalary(int month) { if(super.month == month) { return monthSales * royaltyRate + 100; }else { return monthSales * royaltyRate; } } }
public class Company { public void getSalary(ColaEmployee c,int month) { System.out.println(c.name + "在" + month + "月" + "的月薪为" + c.getSalary(month)+"元"); } }
public class TestCompany { public static void main(String[] args) { ColaEmployee[] cel = { new SalariedEmployee("拿固定工资的员工", 6, 30000), new HourlyEmployee("按小时拿工资的员工", 5, 100, 300), new SalesEmployee("销售人员", 3, 7000000, 0.3) }; for (int i = 0; i < cel.length; i++) { new Company().getSalary(cel[i],7); } } }
package Class; import java.util.Scanner; public class class1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub garderner g = new garderner(); g.creat(); } } class apple implements fruit{ public apple() { System.out.println("种了一个苹果"); } } class banana implements fruit{ public banana() { System.out.println("种了一个香蕉"); } } class putao implements fruit{ public putao() { System.out.println("种了一个葡萄"); } } class garderner{ public fruit creat() { fruit f = null; Scanner input = new Scanner(System.in); String name = input.next(); if(name.equals("苹果")) { f = (fruit) new apple(); } if(name.equals("香蕉")) { f = (fruit) new banana(); } if(name.equals("葡萄")) { f = (fruit) new putao(); } return f; } } interface fruit{ }
以上是关于第十五周作业的主要内容,如果未能解决你的问题,请参考以下文章