shlomibergic

תרגיל 2 - ירושה

Jun 16th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. int salary;
  9. int serial;
  10. int numOfWords;
  11. String name;
  12. Scanner s1 = new Scanner(System.in);
  13. System.out.println("are you a secratry or a programmer? ENTER: S/P");
  14. char type = s1.next().charAt(0);
  15. if ((type == 'S')||(type == 's')){
  16. System.out.println("please enter name, serial number, your salary, and number of words per minute");
  17. name = s1.next();
  18. serial = s1.nextInt();
  19. salary = s1.nextInt();
  20. numOfWords = s1.nextInt();
  21. Employee S1 = new Secratry(name, serial, salary, numOfWords);
  22. System.out.println(S1);
  23. }
  24. else if ((type == 'P')||(type == 'p')) {
  25. System.out.println("please enter name, serial number, your salary");
  26. name = s1.next();
  27. serial = s1.nextInt();
  28. salary = s1.nextInt();
  29. Employee P1 = new Programmer(name, serial, salary);
  30. System.out.println(P1);
  31. }
  32. else
  33.  
  34. System.out.println("not employee");
  35. }
  36. }
  37.  
  38.  
  39. package com.company;
  40.  
  41. public class Employee {
  42. private String name;
  43. int serial, salary;
  44.  
  45. public Employee(String name, int serial, int salary) {
  46. this.name = name;
  47. this.serial = serial;
  48. this.salary = salary;
  49.  
  50. }
  51.  
  52. public String toString() {
  53. return "employee name: " + name + " , serial number: " + serial + " , salary: " + salary;
  54. }
  55.  
  56. public int calcBonus() {
  57. return 0;
  58. }
  59. public void updateSalary(int salary){
  60. this.salary+=salary;
  61. }
  62. }
  63.  
  64. package com.company;
  65.  
  66. public class Programmer extends Employee {
  67.  
  68.  
  69. public Programmer(String name, int serial, int salary) {
  70. super(name, serial, salary);
  71. }
  72.  
  73.  
  74. public int calcBonus(){
  75. return this.salary= salary + salary/2;
  76. }
  77. public String toString(){
  78. return super.toString()+ " new salary after bonus is: " + calcBonus();
  79. }
  80.  
  81. }
  82.  
  83.  
  84. package com.company;
  85.  
  86. public class Secratry extends Employee {
  87. int numOfWords;
  88. public Secratry(String name, int serial, int salary,int numOfWords) {
  89. super(name, serial, salary);
  90. this.numOfWords=numOfWords;
  91. }
  92. public int calcBonus(){
  93. return this.salary=salary+500;
  94. }
  95. public String toString(){
  96. return super.toString()+ " number of words per minute: " + numOfWords + " new salary after bionus: " +calcBonus() ;
  97. }
  98. }
Add Comment
Please, Sign In to add comment