我必须制作一个涉及6个课程的程序。
所以我认为除了EmployeeManager
之外我得到了所有这些。在本课程中,我知道我需要使用EmployeeDriver
中的方法。我不确定如何处理数组,因为我需要输入SalaryEmployee
,HourlyEmployee
和CommissionEmployee
的信息。用户还可以选择列出所有HOurlyEmployees或SalaryEmployees或commisionEmployees
及其信息。我知道我必须遍历数组,但我不知道该怎么做。请帮助我!
答案 0 :(得分:0)
这是一个开始:
import java.math.BigDecimal;
import java.util.*;
abstract class Employee {
Employee(String name) {
this.name = name;
}
final String name;
}
class SalariedEmployee extends Employee {
SalariedEmployee(String name, BigDecimal salary) {
super(name);
this.salary = salary;
}
public String toString() {
return getClass().getSimpleName() + " " + name + " " + salary;
}
final BigDecimal salary;
}
class HourlyEmployee extends Employee {
HourlyEmployee(String name, BigDecimal hourlyRate) {
super(name);
this.hourlyRate = hourlyRate;
}
public String toString() {
return getClass().getSimpleName() + " " + name + " " + hourlyRate;
}
final BigDecimal hourlyRate;
}
class CommissionEmployee extends Employee {
CommissionEmployee(String name, BigDecimal percentage) {
super(name);
this.percentage = percentage;
}
public String toString() {
return getClass().getSimpleName() + " " + name + " " + percentage + "%";
}
final BigDecimal percentage;
}
class Manager {
public String toString() {
return Arrays.asList(employees).toString();
}
Employee[] employees = new Employee[] { new SalariedEmployee("joe", BigDecimal.valueOf(4567.89)),
new HourlyEmployee("mary", BigDecimal.valueOf(12.34)),
new CommissionEmployee("bob", BigDecimal.valueOf(12.34)) };
}
public class Main {
public static void main(String[] args) {
System.out.println(new Manager());
}
}