binibiningtinamoran

Payroll.java

Jun 12th, 2020
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class Payroll {
  4.  
  5.     private final int[] employeeId;
  6.     private final int[] hours;
  7.     private final double[] rate;
  8.  
  9.     public Payroll(int[] employeeId, int[] hours, double[] rate) {
  10.         this.employeeId = employeeId;
  11.         this.hours = hours;
  12.         this.rate = rate;
  13.     }
  14.  
  15.     public int[] getEmployeeId() {
  16.         return employeeId;
  17.     }
  18.  
  19.     public int[] getHours() {
  20.         return hours;
  21.     }
  22.  
  23.     public double[] getRate() {
  24.         return rate;
  25.     }
  26.  
  27.     public double searchEmployee(int id) {
  28.         Arrays.sort(employeeId);
  29.         double grossPay = 0;
  30.         int idx = Arrays.binarySearch(employeeId, id);
  31.         if (idx > -1) {
  32.             grossPay = hours[idx] * rate[idx];
  33.         }
  34.  
  35.         return grossPay;
  36.     }
  37.  
  38.     public double getHighest() {
  39.         double max = rate[0];
  40.         for (double v : rate) {
  41.             if (v > max) {
  42.                 max = v;
  43.             }
  44.         }
  45.         return max;
  46.     }
  47.  
  48.     @Override
  49.     public String toString() {
  50.         String s = "";
  51.  
  52.         for (int i = 0; i < employeeId.length; i++) {
  53.             s += employeeId[i] + "\t\t\t" + hours[i] + "\t\t" + rate[i] + "\n";
  54.         }
  55.         return "Employee ID\tHours\tRate\n" + s;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment