某软件公司年末奖金发放现在需要给公司员工发奖金,其中员工属性有以下五种
其中员工类别分为
各个类别的奖金颁发如下
要求选定一个员工类别,输入工作量,输出奖金并且运用面向对象的思想。
├─.idea
│ .gitignore
│ misc.xml
│ modules.xml
│ uiDesigner.xml
│ workspace.xml
│
├─out
│ └─production
│ └─HW2
│ Intermediate_management.class
│ Intermediate_technologicalManagement.class
│ Intermediate_technology.class
│ Management.class
│ Offer_reward.class
│ Primary_management.class
│ Primary_technologicalManagement.class
│ Primary_technology.class
│ Staff.class
│ Supreme_management.class
│ Supreme_technologicalManagement.class
│ Supreme_technology.class
│ Technical_Management.class
│ Technology.class
│
└─src
Intermediate_management.java
Intermediate_technologicalManagement.java
Intermediate_technology.java
Management.java
Offer_reward.java
Primary_management.java
Primary_technologicalManagement.java
Primary_technology.java
Staff.java
Supreme_management.java
Supreme_technologicalManagement.java
Supreme_technology.java
Technical_Management.java
Technology.java
解答大致分为四部分:程序流程 \ UML \ 代码 \ 运行结果
staff_reward
;该完整代码分为若干个类,并且有普通类也有抽象类,详情请看上方的UML
import java.util.Scanner;
public class Offer_reward {
public static void main(String[] args) {
Staff staff = new Staff();
staff.setStaff_type();
System.out.println("请输入其工作量");
Scanner scanner = new Scanner(System.in);
staff.setStaff_workTime(scanner.nextInt());
if(staff.staff_type == "初级技术工程师"){
Primary_technology primary_technology = new Primary_technology();
primary_technology.setReward(staff.staff_workTime);
// 假如staff_reward不是私有变量则可以这样表示 System.out.println("该员工工资为" + primary_technology.staff_reward);
int reward = primary_technology.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
if (staff.staff_type == "中级技术工程师"){
Intermediate_technology intermediate_technology = new Intermediate_technology();
intermediate_technology.setReward(staff.staff_workTime);
// System.out.println("该员工工资为" + intermediate_technology.staff_reward);
int reward = intermediate_technology.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
if (staff.staff_type == "高级技术工程师"){
Supreme_technology supreme_technology = new Supreme_technology();
supreme_technology.setReward(staff.staff_workTime);
//System.out.println("该员工工资为" + supreme_technology.staff_reward);
int reward = supreme_technology.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
if (staff.staff_type == "普通管理人员"){
Primary_management primary_management = new Primary_management();
primary_management.setReward(staff.staff_workTime);
//System.out.println("该员工工资为" + primary_management.staff_reward);
int reward = primary_management.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
if (staff.staff_type == "中层管理人员"){
Intermediate_management intermediate_management = new Intermediate_management();
intermediate_management.setReward(staff.staff_workTime);
//System.out.println("该员工工资为" + intermediate_management.staff_reward);
int reward = intermediate_management.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
if (staff.staff_type == "高管"){
Supreme_management supreme_management = new Supreme_management();
supreme_management.setReward(staff.staff_workTime);
//System.out.println("该员工工资为" + supreme_management.staff_reward);
int reward = supreme_management.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
if (staff.staff_type == "初级技术管理"){
Primary_technologicalManagement primary_technologicalManagement = new Primary_technologicalManagement();
primary_technologicalManagement.setReward(staff.staff_workTime);
//System.out.println("该员工工资为" + primary_technologicalManagement.staff_reward);
int reward = primary_technologicalManagement.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
if (staff.staff_type == "中级技术管理"){
Intermediate_technologicalManagement intermediate_technologicalManagement = new Intermediate_technologicalManagement();
intermediate_technologicalManagement.setReward(staff.staff_workTime);
//System.out.println("该员工工资为" + intermediate_technologicalManagement.staff_reward);
int reward = intermediate_technologicalManagement.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
if (staff.staff_type == "高级技术管理"){
Supreme_technologicalManagement supreme_technologicalManagement = new Supreme_technologicalManagement();
supreme_technologicalManagement.setReward(staff.staff_workTime);
//System.out.println("该员工工资为" + supreme_technologicalManagement.staff_reward);
int reward = supreme_technologicalManagement.getReward(staff.staff_workTime);
System.out.println("该员工工资为" + reward);
}
}
}
import java.util.Scanner;
public class Staff {
int staff_no;
String staff_name;
int staff_workTime;
private int staff_reward;
String staff_type;
void setStaff_type(){
System.out.println("请输入总员工总类的编号:1为技术类、2为管理类、3为技术管理类");
Scanner scanner = new Scanner(System.in);
int type = scanner.nextInt();
if (type == 1){
System.out.println("当前为技术类,请输入当前员工详细类的等级:1为初级,2为中级,3为高级");
Scanner scanner1 = new Scanner(System.in);
int detailType = scanner1.nextInt();
switch (detailType){
case 1:
this.staff_type = "初级技术工程师";
break;
case 2:
this.staff_type = "中级技术工程师";
break;
case 3:
this.staff_type = "高级技术工程师";
break;
}
}
if (type == 2){
System.out.println("当前为管理类,请输入当前员工详细类的等级:1为普通,2为中层,3为高管");
Scanner scanner1 = new Scanner(System.in);
int detailType = scanner1.nextInt();
switch (detailType) {
case 1:
this.staff_type = "普通管理人员";
break;
case 2:
this.staff_type = "中层管理人员";
break;
case 3:
this.staff_type = "高管";
break;
}
}
if (type == 3){
System.out.println("当前为技术管理类,请输入当前员工详细类的等级:1为初级,2为中级,3为高级");
Scanner scanner1 = new Scanner(System.in);
int detailType = scanner1.nextInt();
switch (detailType) {
case 1:
this.staff_type = "初级技术管理";
break;
case 2:
this.staff_type = "中级技术管理";
break;
case 3:
this.staff_type = "高级技术管理";
break;
}
}
}
void setStaff_workTime(int workTime){
this.staff_workTime = workTime;
}
void setReward(int staff_workTime){}
int getReward(int staff_workTime){ return staff_reward;}
}
abstract class Technology extends Staff{
abstract int getReward(int workTime);
abstract void setReward(int workTime);
}
import javax.swing.text.TabSet;
abstract class Management extends Staff{
abstract int getReward(int workTime);
abstract void setReward(int workTime);
}
import javax.swing.text.TabSet;
abstract class Technical_Management extends Staff{
abstract int getReward(int workTime);
abstract void setReward(int workTime);
}
public class Intermediate_management extends Management{
int staff_reward;
@Override
int getReward(int workTime) {
return (workTime - 50) * 10;
}
void setReward(int workTime){
this.staff_reward = (workTime - 50) * 10;
}
}
public class Intermediate_technologicalManagement extends Technical_Management{
int staff_reward;
@Override
int getReward(int workTime) {
return workTime * 25 + 70;
}
void setReward(int workTime){
this.staff_reward = workTime * 25 + 70;
}
}
public class Intermediate_technology extends Technology{
int staff_reward;
@Override
int getReward(int workTime) {
return workTime*25;
}
void setReward(int workTime){
this.staff_reward = workTime*25;
}
}
public class Primary_management extends Management{
int staff_reward;
@Override
int getReward(int workTime) {
return (workTime - 100) * 5;
}
void setReward(int workTime){
this.staff_reward = (workTime - 100) * 5;
}
}
public class Primary_technologicalManagement extends Technical_Management{
int staff_reward;
@Override
int getReward(int workTime) {
return workTime*25 + 50;
}
void setReward(int workTime){
this.staff_reward = workTime*25 + 50;
}
}
public class Primary_technology extends Technology{
int staff_reward;
@Override
int getReward(int workTime) {
return workTime*20;
}
void setReward(int workTime){
this.staff_reward = workTime * 20;
}
}
public class Supreme_management extends Management{
int staff_reward;
@Override
int getReward(int workTime) {
return workTime * 15;
}
void setReward(int workTime){
this.staff_reward = workTime * 15;
}
}
public class Supreme_technologicalManagement extends Technical_Management{
int staff_reward;
@Override
int getReward(int workTime) {
return workTime * 25 + 100;
}
void setReward(int workTime){
this.staff_reward = workTime * 25 + 100;
}
}
public class Supreme_technology extends Technology{
int staff_reward;
@Override
int getReward(int workTime) {
return workTime*30;
}
void setReward(int workTime){
this.staff_reward = workTime*30;
}
}
如果有疑问欢迎大家留言讨论,你如果觉得这篇文章对你有帮助可以给我一个免费的赞吗?我们之间的交流是我最大的动力!