-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
196 lines (162 loc) · 5.43 KB
/
Copy pathEmployee.java
File metadata and controls
196 lines (162 loc) · 5.43 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
/*import java.util.Scanner;
import java.util.*;
public abstract class Employee
{
protected String firstName; //employee’s name
protected String lastName; //employee’s id
public Employee()
{
firstName = null;
lastName = null;
}
public Employee(String name, String id)
{
firstName = name;
lastName = id;
}
public abstract double earnings();
}
/*class Boss extends Employee
{
protected double weeklySalary; //basic salary of the Boss
protected double sales_amount; //total sales achieved for a given month.
protected double comm_percentage; //commission percentage receive from the total sales
protected final double TAX_PERCENTAGE = 0.15; //only apply to weeklySalary
public Boss(String n,String i,double bonus,double b, double s, double c)
{
super(n,i,bonus);
weeklySalary = b;
sales_amount = s;
comm_percentage = c;
}
public double earnings(double bonus,double basic,double s,double c)
{
double netSalary = 0;
c = c * s;
bonus = (bonus * basic );
netSalary = basic + bonus + c - (s * TAX_PERCENTAGE);
return netSalary;
}
public String toString()
{
return("\nBasic salary: " + weeklySalary +"\nSales amount: " + sales_amount + "\nCommission percentage: " + comm_percentage);
}
}*/
/*class HourlyWorker extends Employee
{
protected int hours; //total hours work for the month.
protected double wage;
public HourlyWorker(String n,String i, int h, double w)
{
super(n,i);
hours = h;
wage = w;
}
public double earnings()
{
double bonus = 200.00;
if(hours > 40)
return hours*wage*bonus;
else
return hours*wage;
}
public String display()
{
return "\nName : "+firstName+" "+lastName +"\nSalary amount: RM" + earnings();
}
}/
class HourlyWorker extends Employee
{
int hours; //total hours work for the month.
double wage;
public HourlyWorker(String n,String i,int h,double w)
{
super(n,i);
hours = h;
wage = w;
}
public double earnings()
{
double bonus = 200.00;
if(hours > 40)
return hours*wage+bonus;
else
return hours*wage;
}
public String display()
{
return "\nName : "+firstName+" "+lastName +"\nSalary amount: RM" + earnings();
}
}
class Boss extends Employee{
protected double weeklySalary; //basic salary of the Boss
public Boss(String n,String i,double b)
{
super(n,i);
weeklySalary = b;
}
public double earnings()
{
return weeklySalary;
}
public String display()
{
return("\nName : "+firstName+" "+lastName +"\nSalary amount: RM" + weeklySalary);
}
}
class testEmploy {
public static void main(String[] args)
{
ArrayList<HourlyWorker> employee = new ArrayList<>();
ArrayList<Boss> boss = new ArrayList<>();
String firstName, lastName, decision, response;
double wage, salary, totalBossEarnings = 0.00, totalWorkerEarnings = 0.00, totalBonus = 0.00, higherstEarnings = -9.99;
int hours, countBoss = 0, countWorker = 0;
Scanner sc = new Scanner(System.in);
Scanner num = new Scanner(System.in);
do {
System.out.println("\n\tInsert First Name :");
firstName= sc.nextLine();
System.out.println("\tInsert Last Name :");
lastName= sc.nextLine();
System.out.println("Boss or HourlyWorker : (B / H)");
decision = sc.nextLine();
if(decision.equalsIgnoreCase("B")){
System.out.println("\n Weekly Salary : RM");
salary = num.nextDouble();
Boss temp = new Boss(firstName,lastName, salary);
boss.add(temp);
countBoss++;
}
else if(decision.equalsIgnoreCase("H")){
System.out.println("\n Wage : RM");
wage = num.nextDouble();
System.out.println("\n Hours : ");
hours = num.nextInt();
HourlyWorker temp = new HourlyWorker(firstName, lastName, hours, wage);
employee.add(temp);
countWorker++;
}
System.out.println("\n\tDo you want to add another order? (Yes/No)");
sc.nextLine();
response = sc.nextLine();
}while(!response.equalsIgnoreCase("no"));
for(int i =0; i<employee.size(); i ++) {
totalWorkerEarnings += employee.get(i).earnings();
if(employee.get(i).earnings()>higherstEarnings)
higherstEarnings = employee.get(i).earnings();
if(employee.get(i).hours>40)
totalBonus += 200.00;
}
for(int i =0; i<boss.size(); i ++) {
totalBossEarnings += boss.get(i).earnings();
}
for(int i=0; i<employee.size(); i++){
if(employee.get(i).hours>48)
System.out.println(employee.get(i).display());
}
sc.close();
num.close();
}
}
*/