Advertisement
advictoriam

Untitled

Dec 11th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. public class Employee
  2. {
  3.    private double salary;
  4.    private static final int OVERTIME_THRESHOLD = 40;
  5.  
  6.    /**
  7.       Constructs an employee with a given salary
  8.       @param anHourlySalary the hourly salary of this employee
  9.    */
  10.    public Employee(double anHourlySalary)
  11.    {
  12.       salary = anHourlySalary;
  13.    }
  14.  
  15.    /**
  16.       Computes the wage for a given week.
  17.       @param hoursWorked the hours worked in the week
  18.       @return the wage earned in that week, taking overtime into account
  19.    */
  20.    public double weeklyWage(int hoursWorked)
  21.    {
  22.       int overtime = (hoursWorked > 40) ? hoursWorked - 40 : 0;
  23.       return (hoursWorked - overtime) * salary + overtime * salary * 1.5;
  24.    }
  25.  
  26.    // this method is used to check your work
  27.  
  28.    public static double check(int hoursWorked)
  29.    {
  30.       Employee emily = new Employee(10); // $10/hour
  31.       return emily.weeklyWage(hoursWorked);
  32.    }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement