Employee类
import java.util.Scanner;
public class Employee {
private int birthdayMonth;
private String name ;
public Employee() {
}
public Employee(String name, int birthdayMouth) {
this.name = name;
this.birthdayMonth = birthdayMouth;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getBirthdayMouth() {
return birthdayMonth;
}
public void setBirthdayMouth(int birthdayMouth) {
this.birthdayMonth = birthdayMouth;
}
public void getSalary(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入月份");
int month = sc.nextInt();
if (month != getBirthdayMouth()){
System.out.println(1000);
}else {
System.out.println(1100);
}
}
}
SalariedEmployee类
import java.util.Scanner;
public class SalariedEmployee extends Employee{
private int gudinggongzi;
public SalariedEmployee() {
}
public SalariedEmployee(int gudinggongzi) {
this.gudinggongzi = gudinggongzi;
}
public SalariedEmployee(String name, int birthdayMouth, int gudinggongzi) {
super(name, birthdayMouth);
this.gudinggongzi = gudinggongzi;
}
public int getGudinggongzi() {
return gudinggongzi;
}
public void setGudinggongzi(int gudinggongzi) {
this.gudinggongzi = gudinggongzi;
}
public void getSalary(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入月份");
int month = sc.nextInt();
if (month != getBirthdayMouth()){
System.out.println("本月工资为:" + getGudinggongzi());
}else {
double gongzi = getGudinggongzi() + 100;
System.out.println("本月工资为:" + gongzi);
}
}
}
HourlyEmployee类
import java.util.Scanner;
public class HourlyEmployee extends Employee{
int hours;
int everyHoursSalary;
public HourlyEmployee() {
}
public HourlyEmployee(int hours, int everyHoursSalary) {
this.hours = hours;
this.everyHoursSalary = everyHoursSalary;
}
public HourlyEmployee(String name, int birthdayMouth, int hours, int everyHoursSalary) {
super(name, birthdayMouth);
this.hours = hours;
this.everyHoursSalary = everyHoursSalary;
}
public int getHours() {
return hours;
}
public void setHours(int hours) {
this.hours = hours;
}
public int getEveryHoursSalary() {
return everyHoursSalary;
}
public void setEveryHoursSalary(int everyHoursSalary) {
this.everyHoursSalary = everyHoursSalary;
}
public void getSalary(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入月份");
int month = sc.nextInt();
double sum = 0;
if(hours <= 160 && hours > 0){
sum = hours * everyHoursSalary;
}else if (hours > 160){
sum = (160 * everyHoursSalary) + ((hours - 160) * (1.5 * everyHoursSalary));
}else {
System.out.println("输入的工作时长不合法");
}
if (month != getBirthdayMouth()){
System.out.println("本月工资为:" + sum);
}else {
sum = sum +100;
System.out.println("本月工资为:" +sum);
}
}
}
SalesEmployee类
import java.util.Scanner;
public class SalesEmployee extends Employee{
double xiaoShouE;
double tiCheng;
public SalesEmployee() {
}
public SalesEmployee(double xiaoShouE, double tiCheng) {
this.xiaoShouE = xiaoShouE;
this.tiCheng = tiCheng;
}
public SalesEmployee(String name, int birthdayMouth, double xiaoShouE, double tiCheng) {
super(name, birthdayMouth);
this.xiaoShouE = xiaoShouE;
this.tiCheng = tiCheng;
}
public double getXiaoShouE() {
return xiaoShouE;
}
public void setXiaoShouE(double xiaoShouE) {
this.xiaoShouE = xiaoShouE;
}
public double getTiCheng() {
return tiCheng;
}
public void setTiCheng(double tiCheng) {
this.tiCheng = tiCheng;
}
public void getSelery(){
double sum = xiaoShouE * tiCheng;
Scanner sc = new Scanner(System.in);
System.out.println("请输入月份");
int month = sc.nextInt();
if (month != getBirthdayMouth()){
System.out.println("本月工资为:" +sum);
}else {
sum = sum + 100;
System.out.println("本月工资为:" + sum);
}
}
}
BasePlusSalesEmployee类
import java.util.Scanner;
public class BasePlusSalesEmployee extends SalariedEmployee{
double xiaoShouE;
double tiCheng;
public BasePlusSalesEmployee() {
}
public BasePlusSalesEmployee(double xiaoShouE, double tiCheng) {
this.xiaoShouE = xiaoShouE;
this.tiCheng = tiCheng;
}
public BasePlusSalesEmployee(int gudinggongzi, double xiaoShouE, double tiCheng) {
super(gudinggongzi);
this.xiaoShouE = xiaoShouE;
this.tiCheng = tiCheng;
}
public BasePlusSalesEmployee(String name, int birthdayMouth, int gudinggongzi, double xiaoShouE, double tiCheng) {
super(name, birthdayMouth, gudinggongzi);
this.xiaoShouE = xiaoShouE;
this.tiCheng = tiCheng;
}
public double getXiaoShouE() {
return xiaoShouE;
}
public void setXiaoShouE(double xiaoShouE) {
this.xiaoShouE = xiaoShouE;
}
public double getTiCheng() {
return tiCheng;
}
public void setTiCheng(double tiCheng) {
this.tiCheng = tiCheng;
}
public void getSalary(){
double gongzi = 0;
int dixin = getGudinggongzi();
Scanner sc = new Scanner(System.in);
System.out.println("请输入月份");
int month = sc.nextInt();
if (month != getBirthdayMouth()){
gongzi = dixin + (xiaoShouE * tiCheng);
}else {
gongzi = dixin + 100 + (xiaoShouE * tiCheng);
}
System.out.println("本月工资为" + gongzi);
}
}
测试类
public class SalaryTest {
public static void main(String[] args) {
SalariedEmployee yuangong1 = new SalariedEmployee(1000);
HourlyEmployee yuangong2 = new HourlyEmployee(180 , 21);
SalesEmployee yuangong3 = new SalesEmployee(9000 , 0.3);
BasePlusSalesEmployee yuangong4 = new BasePlusSalesEmployee(800,7000, 0.25);
yuangong1.getSalary();
yuangong2.getSalary();
yuangong3.getSelery();
yuangong4.getSalary();
}
}