forked from Gersh01/Programming-Assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriverClass.java
More file actions
197 lines (168 loc) · 7.42 KB
/
DriverClass.java
File metadata and controls
197 lines (168 loc) · 7.42 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//Alexander Gershfeld and Gabriel Perez
//Unit 4 Homework 2
//COP3330C
//Hatim Boustique
//9-24-2023
import java.util.ArrayList;
public class DriverClass {
public static void main(String[] args) {
String fullName = "Erika T. Jones";
String employeeNumber = "ej789";
double payRate = 10.50, hoursWorked = 36.00;
// TA will change the pay rate and the hours worked to test your code
Employee e;
e = new Employee(fullName, employeeNumber, payRate, hoursWorked);
System.out.println(e); // To Test your toString method
e.printCheck(); // This prints the check of Erika T. Jones
Company company = new Company();
company.hire ( new Employee ("Saeed Happy", "sh895" , 2 , 200) );
company.hire (e);
company.printCompanyInfo();
company.hire( new Employee("Enrico Torres" , "et897" , 3 , 150) );
company.printEmployees();
System.out.println(company.countEmployees(10000));
//You may add as many employees to company as you want.
//The TAs will add their own employees
//Make sure that each employee of company has a unique employeeNumber
company.printCheck("ab784");
company.deleteEmployeesBySalary(378.00);
company.reverseEmployees();
company.printEmployees();
System.out.println( company.SearchByName("WaLiD WiLLiAms") );
System.out.println(company.countEmployees(10000));
company.printEmployees();
System.out.println("Bye!");
}
}
//____________________________
class Employee {
//Add the private attributes and the methods as mentioned above...
private String fullName;
private String employeeNumber;
private double payRate;
private double hoursWorked;
//Constructor method
public Employee(String fullName, String employeeNumber, double payRate, double hoursWorked) {
setFullName(fullName);
setEmployeeNumber(employeeNumber);
setPayRate(payRate);
setHoursWorked(hoursWorked);
}
//Setters
public void setFullName(String fullName) {this.fullName = fullName;}
public void setEmployeeNumber(String employeeNumber) {this.employeeNumber = employeeNumber;}
public void setPayRate(double payRate) {this.payRate = payRate;}
public void setHoursWorked(double hoursWorked) {this.hoursWorked = hoursWorked;}
//Getters
public String getFullName() {return fullName;}
public String getEmployeeNumber() {return employeeNumber;}
public double getPayRate() {return payRate;}
public double getHoursWorked() {return hoursWorked;}
//Whenever an employee's address is called, return this string; otherwise if called do the same
@Override
public String toString() {
return "[" + employeeNumber + "/" + fullName + ", " + hoursWorked + " Hours @ " + payRate + " per hour]";
}
//Returns the product of payRate and hoursWorked
public double grossPay() {
return (payRate * hoursWorked);
}
//Returns the result of grossPay and calculates the net pay at a 6% tax
private double netPay() {
return grossPay() * .94;
}
//Prints the check of specified employee
public void printCheck() {
System.out.println("---------------------------------------------------------------------------");
System.out.println("\t\tEmployee's name:\t\t" + getFullName());
System.out.println("\t\tEmployee's number:\t\t" + getEmployeeNumber());
System.out.println("\t\tHourly rate of pay:\t\t" + getPayRate());
System.out.println("\t\tHours worked:\t\t\t" + getHoursWorked() + "\n");
System.out.printf("\t\tTotal Gross Pay:%14.2f\n\n", grossPay());
System.out.println("\t\tDeductions");
System.out.printf("\t\tTax (6 %%):%19.2f\n\n", grossPay() - netPay());
System.out.printf("\t\tNet Pay:%22.2f\n\n", netPay());
System.out.println("---------------------------------------------------------------------------");
}
}
//____________________________
class Company {
private ArrayList<Employee> employeeList;
private String companyName;
private static String companyTaxId;
//Initializes the company class
public Company() {
employeeList = new ArrayList<>();
companyName = "People's Place";
companyTaxId = "v1rtua7C0mpan1";
}
//Setter for the company fields
public void setCompanyName(String companyName) {this.companyName = companyName;}
public static void setCompanyTaxId(String companyTaxId) {Company.companyTaxId = companyTaxId;}
//Getters to return the company fields
public String getCompanyName() {return companyName;}
public static String getCompanyTaxId() {return companyTaxId;}
//Searches to see if the employee number of the new employee conflicts with others,
//if not adds to the company array
public boolean hire ( Employee employee ) {
for (Employee value : employeeList) {
if (employee.getEmployeeNumber().compareTo(value.getEmployeeNumber()) == 0)
return false;
}
employeeList.add(employee);
return true;
}
//This method prints the company name, the tax id and the current number of employees
public void printCompanyInfo() {
System.out.println("Company Name: " + getCompanyName() + " | TaxID: " + getCompanyTaxId() + " | Number of Employees:" + employeeList.size());
}
//Prints out the toString of each employee in the list
public void printEmployees() {
int index;
for (index = 0; index < employeeList.size(); index++) {
System.out.println(employeeList.get(index).toString());
}
}
//Counts how many employees earn less than the maxSalary in the entire array
public int countEmployees( double maxSalary ) {
int count = 0;
for (Employee employee : employeeList) {
if (maxSalary > employee.grossPay()) {
count++;
}
}
return count;
}
//Returns true if the array contains the target name; false if there is not a matching name
public boolean SearchByName (String fullName ) {
for (Employee employee : employeeList)
if (fullName.compareToIgnoreCase(employee.getFullName()) == 0)
return true;
return false;
}
//Creates a temporary array that holds the reverse of the company array, replaces the original with reversed
public void reverseEmployees () {
ArrayList<Employee> tmpArr = new ArrayList<>();
for(int j = employeeList.size() - 1; j > -1; j--) {
tmpArr.add(employeeList.get(j));
}
employeeList = tmpArr;
}
//Finds any entries in array that match the targetSalary and removes from the array
public void deleteEmployeesBySalary (double targetSalary ) {
for (int index = 0; index < employeeList.size(); index++)
if (targetSalary == employeeList.get(index).grossPay())
employeeList.remove(index);
}
//Matches employeeNumber to the fields in each entry,
//if there's a match, this method prints the employees check
public void printCheck ( String employeeNumber) {
for (Employee employee : employeeList) {
if (employeeNumber.compareToIgnoreCase(employee.getEmployeeNumber()) == 0) {
employee.printCheck();
return;
}
}
System.out.println("NO SUCH EMPLOYEE EXISTS"); //No matching employee
}
}