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玩过头了 展开
属性: 姓名 name
薪水 salary
还包含一个抽象方法(用来计算周工资)。 abstract public double calcSalary();
派生XSworker(小时工): 按小时支付工资,若每周工作超过40小时,超出部分按1.5支付。
属性: 周工作的小时数 hours
每小时的工资 hourSalary
派生JJworker(计件工): 按产品数量支付。
属性: 产品数量 quantity
每件产品薪水 quantitySalary
派生YJworker(佣金工): 有固定保底周薪,再按照每周销售额提成10%。
属性: 底薪: basePay
销售额: salesMoney
派生Boss(老 板): 每周获得固定周薪
属性: 固定周薪 solidPay
==========全部通过构造函数初始化数据。=======
还有一个输出信息的方法 show 在父类中定义,子类重写
来不及了 明天要交了。。。。汗~玩WOW玩过头了 展开
2个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询