Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Employee {
- String name;
- String position
- public Employee(String name, String position) {
- this.name = name;
- this.position = position
- }
- }
- public class Pilot extends Employee {
- public Pilot(String name,String position) {
- super();
- }
- public void flight() {//flight the plane}
- //getter and setter for the fields
- }
- public class Attendance extends Employee {
- public Attendance(String name,String position) {
- super();
- }
- public Food servingFood(String foodName) {}
- }
- // there will be many other positions
- public class Company {
- HashMap<String, ArrayList<Employee>> employeeTable; //values is a list of workers, key is the position
- public Company() {this.employeeTable = new HashMap<>();}
- public initializeEmployeeTable(file) {} //read file, and create keys in map (file contains information of the position)
- public Worker hireEmployee(String position, String name){
- if (position.equals("pilot")) {
- Pilot p = Pilot(name);
- employeeTable.get("pilot").add(p);
- return p
- }
- else if (position.equals("flightAttendance")) {// the else if statement continuous to check the other position; }
- }
- }
- public static void main(String[] args) {
- Company company = new Company();
- company.initializeEmployeeTable(filePath);
- File eventFile = new File(filePath); // event file describes what's happening in real world; read the lines, and call the program so that program simulates the real world events
- sc = new Scanner(eventFile);
- do {
- String currentEvent = sc.nextLine();
- String[] currentEventParts = currentEvent.split(", ");
- if (currentEvent[0].equals("New Airplane")) { // currentEvent looks like {"New Airplane", "Attendance"// this part can be other position name, "Linda"}
- Worker w = company.hireEmployee(currentEventParts[1], currentEventParts[2]); }
- else if ((currentEvent[0].equals("flying"))) {
- Worker w = company.callEmployee(currentEvent[0], currentEvent[1])
- if (w.getPosition().equals("Pilot")) {(Worker) w.flight()}
- if (w.getPosition().equals("Attendance")) {(Worker) w.serveFood()}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement