/
HospitalPayRoll.java
116 lines (95 loc) · 2.35 KB
/
HospitalPayRoll.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
package general;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class HospitalPayRoll {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<Hospital_Employee> list = new ArrayList<>();
boolean flag=true;
while(flag)
{
System.out.println("Enter the details seperated by comma(,)");
String a=scanner.next();
try {
String[] x=a.split(",");
int id=Integer.parseInt(x[0]);
String des=(x[1]);
int working=Integer.parseInt(x[2]);
int overtime=Integer.parseInt(x[3]);
int salary=0;
if(des.equalsIgnoreCase("Doctor"))
{
salary=working*500+overtime*1000;
}
else if(des.equalsIgnoreCase("Nurse"))
{
salary=working*150+overtime*300;
}
else if(des.equalsIgnoreCase("Reception"))
{
salary=working*100+overtime*200;
}
else {
System.out.println("Enter Proper Designation");
}
Hospital_Employee employee=new Hospital_Employee();
employee.setId(id);
employee.setSalary(salary);
employee.setDesignation(des);
list.add(employee);
}
catch (Exception e) {
System.out.println("Enter Proper Details");
}
System.out.println("Do you want to Continue(Y/N): ");
String val=scanner.next();
if(!val.equalsIgnoreCase("Y"))
{
flag=false;
}
}
Collections.sort(list);
for(Hospital_Employee employee:list)
{
System.out.println("Id : "+employee.getId());
System.out.println("Designation : "+employee.getDesignation());
System.out.println("Salary : "+employee.getSalary());
System.out.println("===============================");
}
scanner.close();
}
}
class Hospital_Employee implements Comparable<Hospital_Employee>
{
private int id;
private String designation;
private int salary;
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
@Override
public int compareTo(Hospital_Employee o) {
if(o.salary<this.salary)
{
return -1;
}
return 0;
}
}