我的代码在OJ上可以运行出来四个结果,但是在Eclips上最后孙悟空运行不出来,也不报错。拜托各位大佬帮我看看哪里出错了,非常感谢♪(・ω・)ノ。
题目:
某公司的员工分为5类,每类员工都有相应的封装类,这5个类的信息如下,
(1) Employee: 这是所有员工的父类。
①属性:员工的姓名、员工的生日月份。
②方法: getSalary(int month)根据参数月份确定工资。如果该月员工过生日,则公司会额外发放100元。
(2) SalariedEmployee: Employee 的子类,拿固定工资的员工。
属性:月薪。
(3) HourlyEmployee: Employee的子类,按小时拿工资的员工,每小时50元,每月工作超出160h的部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数。
(4) SalesEmployee: Employee 的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率
(5) basePlusSalesEmployee: SalesEmployee的子类,有固定底薪的销售人员,工资为底薪加上销售提成。
属性:底薪。
本质要求根据上述员工分类,编写一个程序.实现以下功能,
(1)创建一个Employee数组,分别创建若干不同的Employee 对象,并打印某个月的
(2)每个类都完全封装,不允许有非私有化属性。
注意:该公司规定提成率=月销售额*0.12,固定工资为6000元,销售人员底薪为2800元。
输入格式
按照各个类别属性定义并输入相关信息
样例输入
后羿 6 6000
嫦娥 5 170
牛魔王 7 100000
孙悟空 7 60000
样例输出
后羿-6月份-工资:6000元
嫦娥-5月份-工资:8750元
牛魔王-7月份-工资:12000元
孙悟空-7月份-工资:10000元
我的代码:
import java.util.Scanner;
class Employee{
String name;
int month;
public Employee() {
}
public Employee(String name,int month) {
this.name=name;
this.month=month;
}
void getSalary(int month) {}
}
class SalariedEmployee extends Employee{
static int yuexin=6000;
public SalariedEmployee(){}
public SalariedEmployee(String name,int month,int yuexin){
super(name,month);
this.yuexin=yuexin;
}
void getSalary(int month) {
if(this.month==month) {
yuexin=yuexin+100;
}
else {
yuexin=6000;
}
System.out.print(this.name+"-"+this.month+"月份"+"-"+"工资:"+yuexin+"元");
System.out.println();
}
}
class HourlyEmployee extends Employee{
int hoursale,hour;
public HourlyEmployee() {}
public HourlyEmployee(String name,int month,int hour){
super(name,month);
this.hour=hour;
}
void getSalary(int month) {
if(this.hour<=160) {
hoursale=50*160;
}
else {
hoursale=(int) (50*160+(this.hour-160)*50*1.5);
}
if(this.month==month) {
hoursale=hoursale+100;
}
System.out.print(this.name+"-"+this.month+"月份"+"-"+"工资:"+hoursale+"元");
System.out.println();
}
}
class SalesEmployee extends Employee{
int shoue,tichenglv;
public SalesEmployee() {}
public SalesEmployee(String name,int month,int shoue){
super(name,month);
this.shoue=shoue;
}
void getSalary(int month) {
tichenglv=(int)(this.shoue*0.12);
if(this.month==month) {
tichenglv=tichenglv+100;
}
System.out.print(this.name+"-"+this.month+"月份"+"-"+"工资:"+tichenglv+"元");
System.out.println();
}
}
class basePlusSalesEmployee extends Employee{
static int dixin=2800;
int yueshoue;
public basePlusSalesEmployee() {}
public basePlusSalesEmployee(String name,int month,int yueshoue){
super(name,month);
this.yueshoue=yueshoue;
}
void getSalary(int month) {
int m=0,n=0;
n=(int)(2800+this.yueshoue*0.12);
if(this.month==month) {
m=n+100;
}
else {
m=n;
}
System.out.print(this.name+"-"+this.month+"月份"+"-"+"工资:"+m+"元");
System.out.println();
}
}
public class Gongzi {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
SalariedEmployee sala=new SalariedEmployee(sc.next(),sc.nextInt(),sc.nextInt());
sala.getSalary(8);
HourlyEmployee h=new HourlyEmployee(sc.next(),sc.nextInt(),sc.nextInt());
h.getSalary(8);
SalesEmployee sale=new SalesEmployee(sc.next(),sc.nextInt(),sc.nextInt());
sale.getSalary(8);
basePlusSalesEmployee b=new basePlusSalesEmployee(sc.next(),sc.nextInt(),sc.nextInt());
b.getSalary(8);
}
}
import java.util.Scanner;
// 定义员工类
class Employee {
// 员工姓名
private String name;
// 员工生日月份
private int birthMonth;
// 构造函数
public Employee(String name, int birthMonth) {
this.name = name;
this.birthMonth = birthMonth;
}
// 获取员工姓名
public String getName() {
return name;
}
// 获取员工生日月份
public int getBirthMonth() {
return birthMonth;
}
// 获取指定月份的工资
public double getSalary(int month) {
double salary = 0.0;
// 如果该月是生日月份,则额外发放100元
if (month == birthMonth) {
salary += 100.0;
}
return salary;
}
}
// 定义拿固定工资的员工类
class SalariedEmployee extends Employee {
// 月薪
private double monthlySalary;
// 构造函数
public SalariedEmployee(String name, int birthMonth, double monthlySalary) {
super(name, birthMonth);
this.monthlySalary = monthlySalary;
}
// 获取指定月份的工资
public double getSalary(int month) {
// 调用父类方法获取基本工资
double salary = super.getSalary(month);
// 加上月薪
salary += monthlySalary;
return salary;
}
}
// 定义按小时拿工资的员工类
class HourlyEmployee extends Employee {
// 每小时的工资
private double hourlySalary;
// 每月工作的小时数
private double hoursWorked;
// 构造函数
public HourlyEmployee(String name, int birthMonth, double hourlySalary, double hoursWorked) {
super(name, birthMonth);
this.hourlySalary = hourlySalary;
this.hoursWorked = hoursWorked;
}
// 获取指定月份的工资
public double getSalary(int month) {
// 调用父类方法获取基本工资
double salary = super.getSalary(month);
// 计算加班工资
if (hoursWorked > 160) {
salary += (hoursWorked - 160) * hourlySalary * 1.5;
}
// 加上基本工资
salary += 160 * hourlySalary;
return salary;
}
}
// 定义销售人员类
class SalesEmployee extends Employee {
// 月销售额
private double monthlySales;
// 提成率
private double commissionRate;
// 构造函数
public SalesEmployee(String name, int birthMonth, double monthlySales, double commissionRate) {
super(name, birthMonth);
this.monthlySales = monthlySales;
this.commissionRate = commissionRate;
}
// 获取指定月份的工资
public double getSalary(int month) {
// 调用父类方法获取基本工资
double salary = super.getSalary(month);
// 加上销售提成
salary += monthlySales * commissionRate;
return salary