Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Payroll {
- private final int[] employeeId;
- private final int[] hours;
- private final double[] rate;
- public Payroll(int[] employeeId, int[] hours, double[] rate) {
- this.employeeId = employeeId;
- this.hours = hours;
- this.rate = rate;
- }
- public int[] getEmployeeId() {
- return employeeId;
- }
- public int[] getHours() {
- return hours;
- }
- public double[] getRate() {
- return rate;
- }
- public double searchEmployee(int id) {
- Arrays.sort(employeeId);
- double grossPay = 0;
- int idx = Arrays.binarySearch(employeeId, id);
- if (idx > -1) {
- grossPay = hours[idx] * rate[idx];
- }
- return grossPay;
- }
- public double getHighest() {
- double max = rate[0];
- for (double v : rate) {
- if (v > max) {
- max = v;
- }
- }
- return max;
- }
- @Override
- public String toString() {
- String s = "";
- for (int i = 0; i < employeeId.length; i++) {
- s += employeeId[i] + "\t\t\t" + hours[i] + "\t\t" + rate[i] + "\n";
- }
- return "Employee ID\tHours\tRate\n" + s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment