Guest User

02. Employees

a guest
Oct 24th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. function solveClasses() {
  2.  
  3. class Developer {
  4. constructor(firstName, lastName) {
  5. this.firstName = firstName;
  6. this.lastName = lastName;
  7. this.baseSalary = 1000;
  8. this.tasks = [];
  9. this.experience = 0;
  10. }
  11. addTask(id, taskName, priority) {
  12. if (priority == "high") {
  13. this.tasks.unshift({ id, taskName, priority });
  14. } else {
  15. this.tasks.push({ id, taskName, priority });
  16. }
  17. return `Task id ${id}, with ${priority} priority, has been added.`
  18. }
  19. doTask() {
  20. if (this.tasks.length > 0) {
  21. return this.tasks.shift();
  22. } else {
  23. return `${this.firstName}, you have finished all your tasks. You can rest now.`
  24. }
  25. }
  26. getSalary() {
  27. return `${this.firstName} ${this.lastName} has a salary of: ${this.baseSalary}`;
  28. }
  29. reviewTasks() {
  30. let res = [];
  31. res.push("Tasks, that need to be completed:")
  32. this.tasks.forEach(x => {
  33. res.push(`${x.id}: ${x.taskName} - ${x.priority}`);
  34. })
  35. return res.join('\n');
  36. }
  37. }
  38. class Junior extends Developer {
  39. constructor(firstName, lastName, bonus, experience) {
  40. super(firstName, lastName);
  41. this.experience = experience;
  42. this.baseSalary = 1000 + bonus;
  43. }
  44. learn(years) {
  45. this.experience += years;
  46. }
  47. }
  48. class Senior extends Developer {
  49. constructor(firstName, lastName, bonus, experience) {
  50. super(firstName, lastName);
  51. this.experience = experience + 5;
  52. this.baseSalary = 1000 + bonus;
  53. }
  54. changeTaskPriority(taskId) {
  55. let taskIndex = this.tasks.findIndex(x => x.id == taskId);
  56. let currTask = this.tasks[taskIndex];
  57. this.tasks = this.tasks.splice(taskIndex, 1);
  58. if (currTask.priority == 'low') {
  59. currTask.priority = 'high'
  60. this.tasks.unshift(currTask);
  61. } else {
  62. currTask.priority = 'low';
  63. this.tasks.push(currTask);
  64. }
  65. return currTask;
  66. }
  67.  
  68. }
  69. return {
  70. Developer,
  71. Junior,
  72. Senior
  73. }
  74. }
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment