Advertisement
Ivelin_1936

class Employee

Feb 11th, 2018
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Employee extends Person{
  4.  
  5.     private final static double DEFAULT_OVERTIME_SALARY = 0.0;
  6.  
  7.     private double daySalary;
  8.  
  9.     public Employee(String name, int age, boolean isMan, double daySalary) {
  10.         super(name, age, isMan);
  11.         this.setDaySalary(daySalary);
  12.     }
  13.  
  14.     private void setDaySalary(double daySalary) {
  15.         if (daySalary < 0) {
  16.             throw new IllegalArgumentException("Day salary cannot be negative.");
  17.         }
  18.         this.daySalary = daySalary;
  19.     }
  20.  
  21.     @Override
  22.     public double calculateOvertime(double hours) {
  23.         if (super.getAge() < 18) {
  24.             return DEFAULT_OVERTIME_SALARY;
  25.         } else {
  26.             return getOvertimeMoney(hours);
  27.         }
  28.     }
  29.  
  30.     @Override
  31.     public void showEmployeeInfo() {
  32.         System.out.println(String.format("Name: %s%n" +
  33.                 "Age: %d", super.getName(), super.getAge()));
  34.         if (super.isMan()) {
  35.             System.out.println("Sex: male");
  36.         } else {
  37.             System.out.println("Sex: female");
  38.         }
  39.         System.out.println(String.format("Daily salary: %f%n" , this.daySalary));
  40.     }
  41.  
  42.     private double getOvertimeMoney(double hours) {
  43.         double moneyPerHour = daySalary / 8;
  44.         return hours * (moneyPerHour * 1.5);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement