Advertisement
IvaAnd

class Employee

Oct 5th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package Test;
  2.  
  3. public class Employee {
  4. // constant
  5. private String name;
  6. private double salary;
  7. private String position;
  8.  
  9. // optional
  10. String email;
  11. int age;
  12.  
  13. public Employee(String name, double salary, String position) {
  14. this.name = name;
  15. this.salary = salary;
  16. this.position = position;
  17. this.email = "n/a";
  18. this.age = -1;
  19. }
  20.  
  21. public Employee(String name, double salary, String position, String email, int age) {
  22. this(name, salary, position);
  23. this.email=email;
  24. this.age = age;
  25. }
  26.  
  27. public Employee(String name, double salary, String position, String email) {
  28. this(name, salary, position);
  29. this.email = email;
  30. // int age = -1;
  31. }
  32.  
  33. public Employee(String name, double salary, String position, int age) {
  34. this(name, salary, position);
  35. // this.email = "n/a";
  36. this.age = age;
  37. }
  38.  
  39. @Override
  40. public String toString() {
  41. return String.format("%s %.2f %s %d", this.name, this.salary, this.email, this.age);
  42.  
  43. }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement