desislava_topuzakova

Employee.class

Jun 7th, 2021
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public class Employee {
  2. //name, salary, position, department, email, age
  3.  
  4. //mandatory
  5. private String name;
  6. private double salary;
  7. private String position;
  8. private String department;
  9. //optional
  10. private String email;
  11. private int age;
  12.  
  13.  
  14. //начин 1: name, salary, position, department
  15. public Employee(String name, double salary, String position, String department) {
  16. this.name = name;
  17. this.salary = salary;
  18. this.position = position;
  19. this.department = department;
  20. this.email = "n/a";
  21. this.age = -1;
  22. }
  23.  
  24. //начин 2: name, salary, position, department, email, age
  25. public Employee(String name, double salary, String position, String department, String email, int age) {
  26. this(name, salary, position, department);
  27. this.email = email;
  28. this.age = age;
  29. }
  30.  
  31. //начин 3: name, salary, position, department, email
  32. public Employee(String name, double salary, String position, String department, String email) {
  33. this(name, salary, position, department);
  34. this.email = email;
  35. }
  36. //начин 4: name, salary, position, department, age
  37. public Employee(String name, double salary, String position, String department, int age) {
  38. this(name, salary, position, department);
  39. this.age = age;
  40. }
  41.  
  42. public double getSalary() {
  43. return this.salary;
  44. }
  45.  
  46. @Override
  47. public String toString() {
  48. //"Peter 120.00 [email protected] 28"
  49. return String.format("%s %.2f %s %d", name, salary, email, age);
  50. }
  51.  
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment