JAVA OOP问题

创建一个Employee类(抽象类)属性:姓名name薪水salary还包含一个抽象方法(用来计算周工资)。abstractpublicdoublecalcSalary(... 创建一个Employee类(抽象类)
属性: 姓名 name
薪水 salary

还包含一个抽象方法(用来计算周工资)。 abstract public double calcSalary();

派生XSworker(小时工): 按小时支付工资,若每周工作超过40小时,超出部分按1.5支付。
属性: 周工作的小时数 hours
每小时的工资 hourSalary

派生JJworker(计件工): 按产品数量支付。
属性: 产品数量 quantity
每件产品薪水 quantitySalary

派生YJworker(佣金工): 有固定保底周薪,再按照每周销售额提成10%。
属性: 底薪: basePay
销售额: salesMoney

派生Boss(老 板): 每周获得固定周薪
属性: 固定周薪 solidPay

==========全部通过构造函数初始化数据。=======
还有一个输出信息的方法 show 在父类中定义,子类重写
来不及了 明天要交了。。。。汗~玩WOW玩过头了
展开
 我来答
wangwenjun0609
2009-03-13 · TA获得超过1016个赞
知道小有建树答主
回答量:306
采纳率:0%
帮助的人:302万
展开全部
  public abstract class Employee {
  protected String name = "";

  protected double salary = 0l;

  public Employee() {

  }

  public abstract double calcSalary();

  public abstract void show();

  /**
  * @return Returns the name.
  */
  public String getName() {
  return name;
  }

  /**
  * @param name The name to set.
  */
  public void setName(String name) {
  this.name = name;
  }

  /**
  * @return Returns the salary.
  */
  public double getSalary() {
  return salary;
  }

  /**
  * @param salary The salary to set.
  */
  public void setSalary(double salary) {
  this.salary = salary;
  }

  }
  ========================

  public class XSworker extends Employee {

  private int hours =0;

  private long hourSalary =0l;

  public XSworker(){
  super();
  }

  @Override
  public double calcSalary() {
  double salay = 0;
  if(hours>40){
  salay = hourSalary*40+(hours-40)*hourSalary;
  }else{
  salay=(hours-40)*hourSalary;
  }
  setSalary(salay);
  return salay;
  }

  @Override
  public void show() {
  System.out.println("雇员:"+getName()+",工作时间为:"+getHours()+"工资为:"+getSalary());
  }

  /**
  * @return Returns the hours.
  */
  public int getHours() {
  return hours;
  }

  /**
  * @param hours The hours to set.
  */
  public void setHours(int hours) {
  this.hours = hours;
  }

  /**
  * @return Returns the hourSalary.
  */
  public long getHourSalary() {
  return hourSalary;
  }

  /**
  * @param hourSalary The hourSalary to set.
  */
  public void setHourSalary(long hourSalary) {
  this.hourSalary = hourSalary;
  }

  }
  ====================================

  public class JJworker extends Employee {

  private int quantity =0;
  private double quantitySalary =0d;
  public JJworker(){
  super();
  }

  @Override
  public double calcSalary() {
  double salay = 0;
  salay=quantity*quantitySalary;
  setSalary(salay);
  return salay;
  }

  @Override
  public void show() {
  System.out.println("计件工:"+getName()+",quantity:"+getQuantity()+"工资为:"+getSalary());
  }

  /**
  * @return Returns the quantity.
  */
  public int getQuantity() {
  return quantity;
  }

  /**
  * @param quantity The quantity to set.
  */
  public void setQuantity(int quantity) {
  this.quantity = quantity;
  }

  /**
  * @return Returns the quantitySalary.
  */
  public double getQuantitySalary() {
  return quantitySalary;
  }

  /**
  * @param quantitySalary The quantitySalary to set.
  */
  public void setQuantitySalary(double quantitySalary) {
  this.quantitySalary = quantitySalary;
  }

  }
  =============================

  public class YJworker extends Employee {

  private double basePay = 0d;
  private double salesMoney = 0d;
  public YJworker(){
  super();
  }

  @Override
  public double calcSalary() {
  double sal = 0;
  sal = basePay+salesMoney*0.1;
  setSalary(sal);
  return sal;
  }

  @Override
  public void show() {
  System.out.println("佣金工:"+getName()+",基本工资为:"+getBasePay()+",工资为:"+getSalary());
  }
  /**
  * @return Returns the basePay.
  */
  public double getBasePay() {
  return basePay;
  }

  /**
  * @param basePay The basePay to set.
  */
  public void setBasePay(double basePay) {
  this.basePay = basePay;
  }

  /**
  * @return Returns the salesMoney.
  */
  public double getSalesMoney() {
  return salesMoney;
  }

  /**
  * @param salesMoney The salesMoney to set.
  */
  public void setSalesMoney(double salesMoney) {
  this.salesMoney = salesMoney;
  }

  }
  ===================================

  public class Boss extends Employee {

  private double solidPay =0d;

  public Boss(){
  super();
  }

  @Override
  public double calcSalary() {
  setSalary(solidPay);
  return solidPay;
  }

  @Override
  public void show() {
  System.out.println("老板:"+getName()+"工资为:"+getSalary());
  }

  /**
  * @return Returns the solidPay.
  */
  public double getSolidPay() {
  return solidPay;
  }

  /**
  * @param solidPay The solidPay to set.
  */
  public void setSolidPay(double solidPay) {
  this.solidPay = solidPay;
  }

  }
  ===================================
  简单的测试了一下
  public class TestEmployee {
  public static void main(String[] args) {
  XSworker xsworker = new XSworker();
  xsworker.setName("张三");
  xsworker.setHours(45);
  xsworker.setHourSalary(15);
  xsworker.calcSalary();
  xsworker.show();
  }
  }
  ===============================输出结果为:
  雇员:张三,工作时间为:45工资为:675.0
百度网友f384c78
2009-03-13 · TA获得超过2070个赞
知道小有建树答主
回答量:538
采纳率:0%
帮助的人:717万
展开全部
可怜,为你默哀一秒!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式