-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
47 lines (36 loc) · 1.1 KB
/
Copy pathEmployee.java
File metadata and controls
47 lines (36 loc) · 1.1 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
package com.mosh;
public class Employee {
private int baseSalary;
private int hourlyRate;
public static int numberOfEmployees;
public Employee(int baseSalary, int hourlyRate){
setBaseSalary(baseSalary);
setHourlyRate(hourlyRate);
numberOfEmployees++;
}
public static void printNumberOfEmployees(){
System.out.println(numberOfEmployees);
}
private void setBaseSalary(int baseSalary){
if(baseSalary <=0)
throw new IllegalArgumentException("Salary cannot be 0 or less");
this.baseSalary = baseSalary;
}
private int getBaseSalary(){
return baseSalary;
}
private void setHourlyRate(int hourlyRate){
if(hourlyRate <= 0)
throw new IllegalArgumentException("Hourly rate cannot be 0 or less");
this.hourlyRate = hourlyRate;
}
private int getHourlyRate(){
return hourlyRate;
}
public int calculateWage(int extraHours){
return baseSalary + (hourlyRate * extraHours);
}
public int calculateWage(){
return calculateWage(0);
}
}