forked from tapickell/JavaStuff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPayroll.java
More file actions
128 lines (118 loc) · 2.62 KB
/
Copy pathPayroll.java
File metadata and controls
128 lines (118 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* Payroll
* @author Todd Pickell CISS 238
* Chapter 7
* Programming Challenge 2 pg 504
*/
public class Payroll
{
/**
* private fields
*/
private final int[] employeeId = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489};
private int[] hours = new int[7];
private double[] payRate = new double[7];
private double[] wages = new double[7];
//Setters
/**
* setter method for hours field
* @param hoursIn
* @param indexIn
*/
public void setHours(int hoursIn, int indexIn)
{
hours[indexIn] = hoursIn;
}
/**
* setter method for payRate field
* @param rateIn
* @param indexIn
*/
public void setPayRate(double rateIn, int indexIn)
{
payRate[indexIn] = rateIn;
}
/**
* setter method for wages field
* @param wageIn
* @param indexIn
*/
public void setWages(double wageIn, int indexIn)
{
wages[indexIn] = wageIn;
}
//Getters
/**
* getter method for hours field
* @param indexIn
* @return
*/
public int getHours(int indexIn)
{
return hours[indexIn];
}
/**
* getter method for payRate field
* @param indexIn
* @return
*/
public double getPayRate(int indexIn)
{
return payRate[indexIn];
}
/**
* getter method for wages field
* @param indexIn
* @return
*/
public double getWages(int indexIn)
{
return wages[indexIn];
}
/**
* getter method for employeeId field
* @param indexIn
* @return
*/
public int getEmployeeId(int indexIn)
{
return employeeId[indexIn];
}
public int getNumEmployees()
{
return employeeId.length;
}
/**
* calculates gross pay & saves it to wages field
* takes in employeeId, if Id is not found prints
* error to console and returns -1
* wages and hours must be set before calling this method
* @param idIn
* @return
*/
public double getGrossPay(int idIn)
{
int index = 0;
boolean found = false;
//find employee
for(int i=0; i < employeeId.length; i++)
{
if(employeeId[i] == idIn)
{
index = i;
found = true;
}
}
if(!found)
{
System.out.println("Employee Id doesn't match records.");
return -1;
}
else
{
//calc pay
setWages((getPayRate(index) * getHours(index)), index);
return getWages(index);
}
}
}