Advertisement
desislava_topuzakova

02.CompanyRoster_Employee

Oct 5th, 2020
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. package CompanyRoster;
  2.  
  3. public class Employee {
  4.     //name, salary, position, department, email and age
  5.     //mandatory
  6.     private String name;
  7.     private double salary;
  8.     private String position;
  9.     private String department;
  10.     //optional
  11.     private String email;
  12.     private int age;
  13.  
  14.  
  15.     //1 начин -> name, salary, position, department
  16.     public Employee (String name, double salary, String position, String department) {
  17.         this.name = name;
  18.         this.salary = salary;
  19.         this.position = position;
  20.         this.department = department;
  21.         this.email = "n/a";
  22.         this.age = -1;
  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.     //3 начин -> name, salary, position, department, email
  31.     public Employee (String name, double salary, String position, String department, String email) {
  32.         this(name, salary, position, department);
  33.         this.email = email;
  34.         this.age = -1;
  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.         this.email = "n/a";
  41.     }
  42.  
  43.     public double getSalary() {
  44.         return this.salary;
  45.     }
  46.  
  47.     @Override
  48.     public String toString() {
  49.         return String.format("%s %.2f %s %d", this.name, this.salary, this.email, this.age);
  50.     }
  51.  
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement