-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeeklyPay.java
121 lines (107 loc) · 4.91 KB
/
WeeklyPay.java
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
import java.util.Scanner;
import java.util.Locale;
import java.text.NumberFormat;
public class WeeklyPay
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Employee[] employees = new Employee[100];
int count = 0;
System.out.print("Enter the Employee's Full Name (To exit, enter '0 0'): ");
String fname = input.next();
String lname = input.next();
while(!fname.equalsIgnoreCase("0") && count < 100) {
System.out.printf("Enter the Employee's Contract Type\n"
+ "(S)alaried, (H)ourly, or (C)ommissioned: ");
char type = input.next().charAt(0);
if(type == 'S' || type == 's')
{
System.out.print("\nEnter the Weekly Salary of Employee $");
double salary = input.nextDouble();
System.out.print("Enter 1 for bonus or 0 for non-bonus employee: ");
int review = input.nextInt();
if(review == 1)
{
SalariedEmployee se = new SalariedEmployee(fname, lname, salary, true);
employees[count] = se;
count++;
}
else if(review == 0)
{
SalariedEmployee se = new SalariedEmployee(fname, lname, salary, false);
employees[count] = se;
count++;
}
else
{
System.out.println("Invalid reviewed number.");
}
}
else if(type == 'H' || type == 'h')
{
System.out.print("Enter the amount of hours worked: ");
int hours = input.nextInt();
System.out.print("Enter the rate per hour: $");
double rate = input.nextDouble();
HourlyEmployee he = new HourlyEmployee(fname, lname, hours, rate);
employees[count] = he;
count++;
}
else if(type == 'C' || type == 'c')
{
System.out.print("Enter weekly sales: $");
double sales = input.nextDouble();
CommissionedEmployee ce = new CommissionedEmployee(fname, lname, sales);
employees[count] = ce;
count++;
}
else
{
System.out.println("Invalid type of the employee.");
}
System.out.print("\nEnter the Employee's Full Name (To exit, enter '0 0'): ");
fname = input.next();
lname = input.next();
}
NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);
double total = 0;
//print paysheet (15 spaces per column)
System.out.printf("\n\n%-15s%-12s%12s%12s%10s%15s\n", "Name", "Class",
"Hours", "Sales", "Rate", "Weekly Pay");
System.out.println("================================================================================");
for(int i = 0; i < count; i++)
{
Employee empArray = employees[i];
System.out.printf("%-15s", (empArray.getFirstName() + " " + empArray.getLastName()));
if(empArray instanceof SalariedEmployee)
{
System.out.printf("%-15s%12s%12s%10s%15s", "Salaried", "", "",
"", formatter.format(empArray.calculateWeeklyPay()));
if(((SalariedEmployee) empArray).isBonus())
System.out.print("*");
System.out.println();
total += empArray.calculateWeeklyPay();
}
else if(empArray instanceof HourlyEmployee)
{
System.out.printf("%-15s%12d%12s%10s%15s\n", "Hourly",
((HourlyEmployee) empArray).getHoursWorked(), "",
formatter.format(((HourlyEmployee) empArray).getRateHourly()),
formatter.format(empArray.calculateWeeklyPay()));
total += empArray.calculateWeeklyPay();
}
else if(empArray instanceof CommissionedEmployee)
{
System.out.printf("%-15s%12s%12s%10s%15s\n", "Commissioned", "",
formatter.format(((CommissionedEmployee) empArray).getWeeklySales()),
"", formatter.format(empArray.calculateWeeklyPay()));
total += empArray.calculateWeeklyPay();
}
}//paysheet employee list
System.out.println("================================================================================");
System.out.printf("TOTAL ", formatter.format(total));
System.out.println("*10% bonus");
System.out.println("Thank you for using my program!");
}//main
}//class