以下是基本所需要满足的条件
某软件公司年末奖金发放现在需要给公司员工发奖金,其中员工属性有以下五种
- 编号
- 姓名
- 员工类别
- 总工作量 ( x ) (x) (x)
- 奖金 ( y ) (y) (y)
其中员工类别分为
- 技术类
- 管理类
- 技术管理类
各个类别的奖金颁发如下
- 技术类
y = { x ∗ 30 高级工程师 x ∗ 25 中级工程师 x ∗ 20 初级工程师 y=\begin{cases} &x*30 &高级工程师\\ &x*25 &中级工程师\\ &x*20 &初级工程师 \end{cases} y=⎩ ⎨ ⎧x∗30x∗25x∗20高级工程师中级工程师初级工程师- 管理类
y = { x ∗ 15 高管 ( x − 50 ) ∗ 10 中层管理人员 ( x − 100 ) ∗ 5 普通管理职员 y=\begin{cases} &x*15 &高管\\ &(x-50)*10 &中层管理人员\\ &(x-100)*5 &普通管理职员 \end{cases} y=⎩ ⎨ ⎧x∗15(x−50)∗10(x−100)∗5高管中层管理人员普通管理职员- 技术管理类
y = { x ∗ 25 + 100 高级技术管理类 x ∗ 25 + 70 中级技术管理类 x ∗ 25 + 50 初级技术管理类 y=\begin{cases} &x*25+100 &高级技术管理类\\ &x*25+70 &中级技术管理类\\ &x*25+50 &初级技术管理类 \end{cases} y=⎩ ⎨ ⎧x∗25+100x∗25+70x∗25+50高级技术管理类中级技术管理类初级技术管理类
要求选定一个员工类别,输入工作量,输出奖金并且运用面向对象的思想
所需要满足新的要求如下
├─.idea
│ .gitignore
│ encodings.xml
│ misc.xml
│ modules.xml
│ uiDesigner.xml
│ workspace.xml
│
├─out
│ └─production
│ └─HW2
│ IntermediateManaFactor.class
│ IntermediateTecFactor.class
│ IntermediateTecManaFactor.class
│ Intermediate_management.class
│ Intermediate_technologicalManagement.class
│ Intermediate_technology.class
│ Management.class
│ Offer_reward.class
│ PrimaryManaFactor.class
│ PrimaryTecFactor.class
│ PrimaryTecManaFactor.class
│ Primary_management.class
│ Primary_technologicalManagement.class
│ Primary_technology.class
│ Staff.class
│ StaffFactory.class
│ SuperManaFactor.class
│ SuperTecFactor.class
│ SuperTecManaFactor.class
│ Supreme_management.class
│ Supreme_technologicalManagement.class
│ Supreme_technology.class
│ Technical_Management.class
│ Technology.class
│
└─src
IntermediateManaFactor.java
IntermediateTecFactor.java
IntermediateTecManaFactor.java
Intermediate_management.java
Intermediate_technologicalManagement.java
Intermediate_technology.java
Management.java
Offer_reward.java
PrimaryManaFactor.java
PrimaryTecFactor.java
PrimaryTecManaFactor.java
Primary_management.java
Primary_technologicalManagement.java
Primary_technology.java
Staff.java
StaffFactory.java
SuperManaFactor.java
SuperTecFactor.java
SuperTecManaFactor.java
Supreme_management.java
Supreme_technologicalManagement.java
Supreme_technology.java
Technical_Management.java
Technology.java
该项目采用的模式为工厂模式
由于类过多所以只展示了部分核心的代码快照
import java.util.Scanner;
public class Offer_reward {
public static void main(String[] args) {
int StaffType; //员工的类型
System.out.println("请选择员工的类别:1.初级技术工程师;2.中级技术工程师;3.高级技术工程师;4.普通管理人员;5.中层管理人员;6.高管;7.初级技术管理人员;8.中级技术管理人员;9.高级技术管理人员");
Scanner scanner = new Scanner(System.in);
StaffType = scanner.nextInt();
StaffFactory factory = null;
switch (StaffType){
case 1:
factory = new PrimaryTecFactor();
break;
case 2:
factory = new IntermediateTecFactor();
break;
case 3:
factory = new SuperTecFactor();
break;
case 4:
factory = new PrimaryManaFactor();
break;
case 5:
factory = new IntermediateManaFactor();
break;
case 6:
factory = new SuperManaFactor();
break;
case 7:
factory = new PrimaryTecManaFactor();
break;
case 8:
factory = new IntermediateTecManaFactor();
break;
case 9:
factory = new SuperTecManaFactor();
break;
}
int workTime; //员工的工作时间
System.out.println("请输入员工的工作时间");
Scanner scanner1 = new Scanner(System.in);
workTime = scanner1.nextInt();
factory.setWorkTime(workTime);
boolean taxes; //是否收税
System.out.println("是否收税呢?");
Scanner scanner2 = new Scanner(System.in);
taxes = scanner2.nextBoolean();
int reward; //工资
Staff staff = factory.createStaff();
reward = staff.getReward(factory.getWorkTime(),taxes);
System.out.println("该员工的工资为" + reward);
}
}
public interface Staff {
int getReward(int workTime, boolean taxes);
int getReward(int workTime, boolean taxes, int subsidy);
int getSubsidy(int workTime);
}
public interface StaffFactory {
Staff createStaff();
void setWorkTime(int workTime);
int getWorkTime();
}
public class Intermediate_management extends Management{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = (workTime - 50) * 10;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
}
public class Intermediate_technologicalManagement extends Technical_Management{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = workTime * 25 + 70;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
}
public class Intermediate_technology extends Technology{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = workTime*25;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
@Override
public int getReward(int workTime, boolean taxes, int subsidy) {
int salary = workTime*25;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97 + subsidy);
}
else {
return salary + subsidy;
}
}
}
public class IntermediateManaFactor implements StaffFactory{
private int workTime;
@Override
public Staff createStaff() {
return new Intermediate_management();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
public class IntermediateTecFactor implements StaffFactory{
int workTime;
@Override
public Staff createStaff() {
return new Intermediate_technology();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
public class IntermediateTecManaFactor implements StaffFactory{
private int workTime;
@Override
public Staff createStaff() {
return new Intermediate_technologicalManagement();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
abstract class Management implements Staff{
@Override
public abstract int getReward(int workTime, boolean taxes);
public int getReward(int workTime, boolean taxes, int subsidy){
return 0;
};
@Override
public int getSubsidy(int workTime) {
return 0;
}
}
public class Primary_management extends Management{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = (workTime - 100) * 5;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
}
public class Primary_technologicalManagement extends Technical_Management{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = workTime*25 + 50;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
}
public class Primary_technology extends Technology{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = workTime * 20;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
@Override
public int getSubsidy(int workTime) {
return 1500;
}
@Override
public int getReward(int workTime, boolean taxes, int subsidy) {
int salary = workTime*25;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97 + subsidy);
}
else {
return salary + subsidy;
}
}
}
public class PrimaryManaFactor implements StaffFactory{
private int workTime;
@Override
public Staff createStaff() {
return new Primary_management();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
public class PrimaryTecFactor implements StaffFactory{
private int workTime;
@Override
public Staff createStaff() {
return new Primary_technology();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
public class PrimaryTecManaFactor implements StaffFactory{
private int workTime;
@Override
public Staff createStaff() {
return new Primary_technologicalManagement();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
public class SuperManaFactor implements StaffFactory{
private int workTime;
@Override
public Staff createStaff() {
return new Supreme_management();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
public class SuperTecFactor implements StaffFactory{
int workTime;
@Override
public Staff createStaff() {
return new Supreme_technology();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
public class SuperTecManaFactor implements StaffFactory{
private int workTime;
@Override
public Staff createStaff() {
return new Supreme_technologicalManagement();
}
@Override
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
@Override
public int getWorkTime() {
return workTime;
}
}
public class Supreme_management extends Management{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = workTime * 15;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
}
public class Supreme_technologicalManagement extends Technical_Management{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = workTime * 25 + 100;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
}
public class Supreme_technology extends Technology{
@Override
public int getReward(int workTime, boolean taxes) {
int salary = workTime*30;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97);
}
else {
return salary;
}
}
@Override
public int getReward(int workTime, boolean taxes, int subsidy) {
int salary = workTime*25;
if (taxes && salary >= 5000) {
return (int) (salary * 0.97 + subsidy);
}
else {
return salary + subsidy;
}
}
}
abstract class Technical_Management implements Staff{
public abstract int getReward(int workTime, boolean taxes);
@Override
public int getReward(int workTime, boolean taxes, int subsidy) {
return 0;
}
@Override
public int getSubsidy(int workTime) {
return 0;
}
}
abstract class Technology implements Staff{
public abstract int getReward(int workTime, boolean taxes);
@Override
public abstract int getReward(int workTime, boolean taxes, int subsidy);
@Override
public int getSubsidy(int workTime) {
return 1000;
}
}
如果有疑问欢迎大家留言讨论,你如果觉得这篇文章对你有帮助可以给我一个免费的赞吗?我们之间的交流是我最大的动力!