java代码 java代码试根据已学内容实现一个管理系统(内容不限)。例如员工工资结算的管理系统。在该系统中,员工分为普通员工和管理人员两类,普通员工的工资由基本工资、奖金和加班费组成,管理人员的工资在普通员工的工资上增加了福利。员工工资结算管理系统主要功能可包括:(1)查看全部普通员工信息;(2)添加普通员工;(3)普通员工工资结算;(4)查看全部管理人员信息;(5)添加管理人员;(6)管理人员工资结算。
时间: 2024-03-23 10:36:24 浏览: 73
以下是简单的员工工资结算管理系统的Java代码实现,实现了添加员工、计算员工工资、查看员工信息等功能。代码中包括一个Employee类,用来表示员工信息,以及一个Manager类,继承自Employee类,表示管理人员。还有一个SalaryCalculator类,用来计算员工工资。
```java
import java.util.ArrayList;
import java.util.Scanner;
//员工类
class Employee {
private String name; //姓名
private int baseSalary; //基本工资
private int bonus; //奖金
private int overtime; //加班费
public Employee(String name, int baseSalary, int bonus, int overtime) {
this.name = name;
this.baseSalary = baseSalary;
this.bonus = bonus;
this.overtime = overtime;
}
//计算工资
public int calculateSalary() {
return baseSalary + bonus + overtime;
}
//显示员工信息
public void displayInfo() {
System.out.println("姓名:" + name);
System.out.println("基本工资:" + baseSalary);
System.out.println("奖金:" + bonus);
System.out.println("加班费:" + overtime);
System.out.println("工资总额:" + calculateSalary());
}
}
//管理人员类
class Manager extends Employee {
private int welfare; //福利
public Manager(String name, int baseSalary, int bonus, int overtime, int welfare) {
super(name, baseSalary, bonus, overtime);
this.welfare = welfare;
}
//计算工资
public int calculateSalary() {
return super.calculateSalary() + welfare;
}
}
//工资计算器
class SalaryCalculator {
private ArrayList<Employee> employees; //员工列表
public SalaryCalculator() {
employees = new ArrayList<Employee>();
}
//添加员工
public void addEmployee(Employee employee) {
employees.add(employee);
}
//添加管理人员
public void addManager(Manager manager) {
employees.add(manager);
}
//计算所有员工工资
public void calculateAllSalary() {
for (Employee employee : employees) {
employee.displayInfo();
}
}
//查看所有员工信息
public void displayAllEmployees() {
for (Employee employee : employees) {
employee.displayInfo();
}
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
SalaryCalculator salaryCalculator = new SalaryCalculator();
//添加普通员工
System.out.println("请输入员工姓名:");
String name = scanner.nextLine();
System.out.println("请输入员工基本工资:");
int baseSalary = scanner.nextInt();
System.out.println("请输入员工奖金:");
int bonus = scanner.nextInt();
System.out.println("请输入员工加班费:");
int overtime = scanner.nextInt();
Employee employee = new Employee(name, baseSalary, bonus, overtime);
salaryCalculator.addEmployee(employee);
//添加管理人员
System.out.println("请输入管理人员姓名:");
scanner.nextLine();
name = scanner.nextLine();
System.out.println("请输入管理人员基本工资:");
baseSalary = scanner.nextInt();
System.out.println("请输入管理人员奖金:");
bonus = scanner.nextInt();
System.out.println("请输入管理人员加班费:");
overtime = scanner.nextInt();
System.out.println("请输入管理人员福利:");
int welfare = scanner.nextInt();
Manager manager = new Manager(name, baseSalary, bonus, overtime, welfare);
salaryCalculator.addManager(manager);
//计算所有员工工资并显示员工信息
salaryCalculator.calculateAllSalary();
//查看所有员工信息
salaryCalculator.displayAllEmployees();
}
}
```
此代码只是一个简单的示例,实际应用中还需要考虑员工信息的存储、修改和删除等功能,以及更完善的错误处理和界面设计。
阅读全文