-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPayroll.java
126 lines (119 loc) · 4.43 KB
/
Payroll.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
122
123
124
125
126
import packs.*;
import java.util.*;
class Payroll
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Payroll pay = new Payroll();
System.out.println("Categories of Employees : ");
System.out.println("1) Salaried Employee.");
System.out.println("2) Commission Employee.");
System.out.println("3) Base Plus Commission Employee.");
System.out.println("4) Hourly Employee.");
System.out.println("Enter your choice : ");
int cho = sc.nextInt();
double totalEarnings;
System.out.println("Enter the First name of the employee : ");
final String fname = sc.next();
System.out.println("Enter the Last name of the employee : ");
final String lname = sc.next();
System.out.println("Enter the Social Security number of the employee : ");
final long ssn = sc.nextLong();
System.out.println("Enter yes or no to state if the employee has recieved bonus : ");
String bcho = sc.next();
Boolean bonus;
double bonus_amt = 0;
if(bcho.equalsIgnoreCase("yes") || bcho.equalsIgnoreCase("y"))
{
bonus = true;
System.out.println("Enter the bonus amount recieved : ");
bonus_amt = sc.nextDouble();
}
else
{
bonus = false;
}
if(cho==1)
{
System.out.println("Enter the Weekly Salary of the employee : ");
double weekly = sc.nextDouble();
SalariedEmployee ob = new SalariedEmployee(fname, lname, ssn, weekly);
if(bonus)
{
totalEarnings = ob.earnings(bonus_amt);
}
else
{
totalEarnings = ob.earnings();
}
pay.printDetails(fname, lname, ssn, totalEarnings);
}
else if(cho==2)
{
System.out.println("Enter the Gross sales of the employee : ");
double gsale = sc.nextDouble();
System.out.println("Enter the Commission rate of the employee : ");
double crate = sc.nextDouble();
Payable ob = new CommissionEmployee(fname, lname, ssn, gsale, crate);
if(bonus)
{
totalEarnings = ob.earnings(bonus_amt);
}
else
{
totalEarnings = ob.earnings();
}
pay.printDetails(fname, lname, ssn, totalEarnings);
}
else if(cho==3)
{
System.out.println("Enter the Gross sales of the employee : ");
double gsale = sc.nextDouble();
System.out.println("Enter the Basic Salary of the employee : ");
double basic = sc.nextDouble();
System.out.println("Enter the Commission rate of the employee : ");
double crate = sc.nextDouble();
Payable ob = new BasePlusCommissionEmployee(fname, lname, ssn, gsale, crate, basic);
if(bonus)
{
totalEarnings = ob.earnings(bonus_amt);
}
else
{
totalEarnings = ob.earnings();
}
pay.printDetails(fname, lname, ssn, totalEarnings);
}
else if(cho==4)
{
System.out.println("Enter the Hourly Wage of the employee : ");
double hwage = sc.nextDouble();
System.out.println("Enter the total working hours of the employee : ");
int hour = sc.nextInt();
Payable ob = new HourlyEmployee(fname, lname, ssn, hwage, hour);
if(bonus)
{
totalEarnings = ob.earnings(bonus_amt);
}
else
{
totalEarnings = ob.earnings();
}
pay.printDetails(fname, lname, ssn, totalEarnings);
}
else
{
System.out.println("Wrong Input");
}
sc.close();
}
void printDetails(String fname, String lname, long ssn, double totalEarnings)
{
System.out.println("--------------------------------------------------------------------------");
System.out.println("Employee Name : " + fname + " " + lname);
System.out.println("Social Security Number : " + ssn);
System.out.println("Total Salary = " + totalEarnings);
System.out.println("--------------------------------------------------------------------------");
}
}