-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployees.java
More file actions
49 lines (38 loc) · 943 Bytes
/
Employees.java
File metadata and controls
49 lines (38 loc) · 943 Bytes
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
package Lec50;
import java.util.*;
public class Employees {
String name;
int salary;
public Employees(String name, int salary) {
// TODO Auto-generated constructor stub
this.name = name;
this.salary = salary;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int n = sc.nextInt();
Employees[] emp = new Employees[n];
for (int i = 0; i < emp.length; i++) {
String str = sc.next();
int s = sc.nextInt();
emp[i] = new Employees(str, s);
}
Arrays.sort(emp,new Comparator<Employees>() {
@Override
public int compare(Employees o1, Employees o2) {
if(o1.salary==o2.salary) {
return o1.name.compareTo(o2.name);
}
else {
return o2.salary-o1.salary;
}
}
});
for (int i = 0; i < emp.length; i++) {
if (emp[i].salary >= x) {
System.out.println(emp[i].name + " " + emp[i].salary);
}
}
}
}