Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Payroll {
- private int NUM_EMPLOYEES = 7;
- private int[] employeeID, hours;
- private double[] payRate, wages;
- public Payroll()
- {
- employeeID = new int[NUM_EMPLOYEES];
- hours = new int[NUM_EMPLOYEES];
- payRate = new double[NUM_EMPLOYEES];
- wages = new double[NUM_EMPLOYEES];
- }
- public double getGrossPay(int i)
- {
- return hours[i] * payRate[i];
- }
- public void setEmployeeIDAt(int i, int id)
- {
- employeeID[i] = id;
- }
- public void setHoursAt(int i, int h)
- {
- hours[i] = h;
- }
- public void setPayRateAt(int i, double p)
- {
- payRate[i] = p;
- }
- public void setWagesAt(int i, double w)
- {
- wages = new double[NUM_EMPLOYEES];
- wages[i] = w;
- }
- public int getEmployeeIdAt(int i)
- {
- return employeeID[i];
- }
- public int getHoursAt(int i)
- {
- return hours[i];
- }
- public double getPayRateAt(int i)
- {
- return payRate[i];
- }
- public double getWagesAt(int i)
- {
- return wages[i];
- }
- }
- import java.util.Scanner;
- public class PayrollDemo {
- public static void main(String[] args) {
- int[] employeeID = {5658845,4520125,7895122,8777541,8451277,1302850,7580489};
- int[] hours;
- double[] payRate, wages;
- int eId;
- Scanner input = new Scanner(System.in);
- Payroll acct = new Payroll();
- for (int index = 0; index < employeeID.length - 4; index++)
- {
- eId = employeeID[index];
- acct.setEmployeeIDAt(index, eId);
- System.out.print("Enter the hours worked by employee number " + acct.getEmployeeIdAt(index) + ": ");
- hours = new int[employeeID.length];
- hours[index] = input.nextInt();
- acct.setHoursAt(index, hours[index]);
- System.out.print("Enter the hourly pay rate for employee number " + acct.getEmployeeIdAt(index) + ": ");
- payRate = new double[employeeID.length];
- payRate[index] = input.nextDouble();
- acct.setPayRateAt(index, payRate[index]);
- }
- System.out.println("\nPAYROLL DATA");
- System.out.println("==================");
- for (int index = 0; index < employeeID.length -4; index ++)
- {
- System.out.println("Employee " acct.getEmployeeIdAt(index) + " " +
- acct.getGrossPay(index));
- }
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement