dm6801

171127 - Class 08 - Employee

Nov 29th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. package Class;
  2.  
  3. public class Employee {
  4.    
  5.     /* properties */
  6.     protected String name;
  7.     protected int uniqueID;
  8.     protected float salary;
  9.    
  10.     protected final static float SALARY_MIN = .0f;
  11.     protected static int uid_count = 1000;
  12.    
  13.    
  14.     /* set, get methods */
  15.     public void setName(String name) {
  16.         this.name = name;
  17.        
  18.     }
  19.     public String getName() { return this.name; }
  20.     public void setUniqueID(int uniqueID) {
  21.         if (uniqueID < 1000) { uniqueID = uid_count; }
  22.        
  23.         this.uniqueID = uniqueID;
  24.        
  25.     }
  26.     public int getUniqueID() { return this.uniqueID; }
  27.     public void setSalary(float salary) {
  28.         this.salary = salary;
  29.        
  30.     }
  31.     public float getSalary() { return this.salary; }
  32.    
  33.    
  34.     /* constructors */
  35.     public Employee(String name, int uniqueID, float salary) {
  36.         this.setName(name);
  37.         this.setUniqueID(uniqueID);
  38.         this.setSalary(salary);
  39.        
  40.         uidCountInc();
  41.     }
  42.     public Employee(String name, int uniqueID) {
  43.         this(name, uniqueID, SALARY_MIN);
  44.     }
  45.     public Employee(String name) {
  46.         this(name, uid_count, SALARY_MIN);
  47.     }
  48.    
  49.    
  50.     /* methods */
  51.     public String toString() {
  52.         String str = String.format("(%s@%h)\tname=%s\tuid=%d\tsalary=%.2f",
  53.                                     this.getClass().getName(), this, name, uniqueID, salary);
  54.         return str;
  55.     }
  56.    
  57.     public static void uidCountInc() {
  58.         uid_count += 1;
  59.     }
  60.    
  61.     public float calcBonus() {
  62.         return this.salary; //no bonus
  63.     }
  64.    
  65.     public boolean updateSalary(float salary) {
  66.         float oldSalary = this.salary;
  67.         setSalary(salary);
  68.         return (oldSalary != this.salary)?true:false;
  69.     }
  70.    
  71. }
Add Comment
Please, Sign In to add comment