Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1.  
  2. public class SalariedEmployee extends Employee
  3. {
  4.     private double salary;
  5.    
  6.     public SalariedEmployee()
  7.     {
  8.         super();
  9.         salary = 0;
  10.     }
  11.    
  12.     public SalariedEmployee(String theName, Date theDate, double theSalary)
  13.     {
  14.         super(theName, theDate);
  15.         if(theSalary >= 0)
  16.             salary = theSalary;
  17.         else
  18.         {
  19.             System.out.println("Fatal Error: Negative slary.");
  20.             System.exit(0);
  21.         }
  22.     }
  23.    
  24.     public SalariedEmployee(SalariedEmployee originalObject)
  25.     {
  26.         super(originalObject);
  27.         salary = originalObject.salary;
  28.     }
  29.    
  30.     public double getSalary()
  31.     {
  32.         return salary;
  33.     }
  34.    
  35.     public double getPay()
  36.     {
  37.         return salary/12;
  38.     }
  39.    
  40.     public void setSalary(double newSalary)
  41.     {
  42.         if(newSalary >= 0)
  43.             salary = newSalary;
  44.         else
  45.         {
  46.             System.out.println("Fatal Error: Negative Salary.");
  47.             System.exit(0);
  48.         }
  49.     }
  50.    
  51.     public String toString()
  52.     {
  53.         return (getName() + " " + getHireDate().toString() + "\n$" + salary + " per year");    
  54.     }
  55.    
  56.     public boolean equals(SalariedEmployee other)
  57.     {
  58.         return(getName().equals(other.getName()) && getHireDate().equals(other.getHireDate())
  59.                 && salary == other.salary);
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement