-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeTest.java
More file actions
82 lines (66 loc) · 2.3 KB
/
EmployeeTest.java
File metadata and controls
82 lines (66 loc) · 2.3 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
import java.util.Scanner;
class Employee {
String firstName;
String lastName;
double monthlySalary;
Employee(String fName, String lName, double salary) {
firstName = fName;
lastName = lName;
if (salary > 0)
monthlySalary = salary;
}
void setFirstName(String fName) {
firstName = fName;
}
void setLastName(String lName) {
lastName = lName;
}
void setMonthlySalary(double salary) {
if (salary > 0)
monthlySalary = salary;
}
String getFirstName() {
return firstName;
}
String getLastName() {
return lastName;
}
double getMonthlySalary() {
return monthlySalary;
}
}
public class EmployeeTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Employee 1
System.out.println("Enter details of Employee 1:");
System.out.print("First Name: ");
String f1 = sc.nextLine();
System.out.print("Last Name: ");
String l1 = sc.nextLine();
System.out.print("Monthly Salary: ");
double s1 = sc.nextDouble();
sc.nextLine();
// Employee 2
System.out.println("\nEnter details of Employee 2:");
System.out.print("First Name: ");
String f2 = sc.nextLine();
System.out.print("Last Name: ");
String l2 = sc.nextLine();
System.out.print("Monthly Salary: ");
double s2 = sc.nextDouble();
Employee e1 = new Employee(f1, l1, s1);
Employee e2 = new Employee(f2, l2, s2);
// Yearly salary
System.out.println("\nYearly Salaries:");
System.out.println(e1.getFirstName() + " : " + (e1.getMonthlySalary() * 12));
System.out.println(e2.getFirstName() + " : " + (e2.getMonthlySalary() * 12));
// 10% hike
e1.setMonthlySalary(e1.getMonthlySalary() * 1.10);
e2.setMonthlySalary(e2.getMonthlySalary() * 1.10);
// After hike
System.out.println("\nYearly Salaries after 10% hike:");
System.out.println(e1.getFirstName() + " : " + (e1.getMonthlySalary() * 12));
System.out.println(e2.getFirstName() + " : " + (e2.getMonthlySalary() * 12));
}
}