Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public abstract class Employee {
  2. String name;
  3. String position
  4. public Employee(String name, String position) {
  5. this.name = name;
  6. this.position = position
  7. }
  8. }
  9.  
  10. public class Pilot extends Employee {
  11. public Pilot(String name,String position) {
  12. super();
  13. }
  14. public void flight() {//flight the plane}
  15. //getter and setter for the fields
  16. }
  17.  
  18. public class Attendance extends Employee {
  19. public Attendance(String name,String position) {
  20. super();
  21. }
  22. public Food servingFood(String foodName) {}
  23.  
  24. }
  25.  
  26. // there will be many other positions
  27.  
  28.  
  29. public class Company {
  30.  
  31. HashMap<String, ArrayList<Employee>> employeeTable; //values is a list of workers, key is the position
  32.  
  33. public Company() {this.employeeTable = new HashMap<>();}
  34. public initializeEmployeeTable(file) {} //read file, and create keys in map (file contains information of the position)
  35. public Worker hireEmployee(String position, String name){
  36. if (position.equals("pilot")) {
  37. Pilot p = Pilot(name);
  38. employeeTable.get("pilot").add(p);
  39. return p
  40. }
  41. else if (position.equals("flightAttendance")) {// the else if statement continuous to check the other position; }
  42. }
  43. }
  44.  
  45.  
  46.  
  47. public static void main(String[] args) {
  48. Company company = new Company();
  49. company.initializeEmployeeTable(filePath);
  50. 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
  51. sc = new Scanner(eventFile);
  52. do {
  53. String currentEvent = sc.nextLine();
  54. String[] currentEventParts = currentEvent.split(", ");
  55. if (currentEvent[0].equals("New Airplane")) { // currentEvent looks like {"New Airplane", "Attendance"// this part can be other position name, "Linda"}
  56. Worker w = company.hireEmployee(currentEventParts[1], currentEventParts[2]); }
  57. else if ((currentEvent[0].equals("flying"))) {
  58. Worker w = company.callEmployee(currentEvent[0], currentEvent[1])
  59. if (w.getPosition().equals("Pilot")) {(Worker) w.flight()}
  60. if (w.getPosition().equals("Attendance")) {(Worker) w.serveFood()}
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement