Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Employee extends Person{
- private final static double DEFAULT_OVERTIME_SALARY = 0.0;
- private double daySalary;
- public Employee(String name, int age, boolean isMan, double daySalary) {
- super(name, age, isMan);
- this.setDaySalary(daySalary);
- }
- private void setDaySalary(double daySalary) {
- if (daySalary < 0) {
- throw new IllegalArgumentException("Day salary cannot be negative.");
- }
- this.daySalary = daySalary;
- }
- @Override
- public double calculateOvertime(double hours) {
- if (super.getAge() < 18) {
- return DEFAULT_OVERTIME_SALARY;
- } else {
- return getOvertimeMoney(hours);
- }
- }
- @Override
- public void showEmployeeInfo() {
- System.out.println(String.format("Name: %s%n" +
- "Age: %d", super.getName(), super.getAge()));
- if (super.isMan()) {
- System.out.println("Sex: male");
- } else {
- System.out.println("Sex: female");
- }
- System.out.println(String.format("Daily salary: %f%n" , this.daySalary));
- }
- private double getOvertimeMoney(double hours) {
- double moneyPerHour = daySalary / 8;
- return hours * (moneyPerHour * 1.5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement