-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSem2_T3_13.java
More file actions
46 lines (39 loc) · 1.26 KB
/
Sem2_T3_13.java
File metadata and controls
46 lines (39 loc) · 1.26 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
import java.util.*;
/* -> Create a class named Team eith 3 instance variable name, Wcount, Lcount.
* -> through psvm create 5 team and store them in priority queue.
* -> for the upcoming match remove 2 teams from the queue which has highest Win Lose
* Difference and print the name of these 2 teams.
*/
class Team {
String name;
int Wcount;
int Lcount;
public Team(String name, int wcount, int lcount) {
this.name = name;
Wcount = wcount;
Lcount = lcount;
}
public int getWL() {
return Wcount - Lcount;
}
}
public class Sem2_T3_13 {
public static void main(String[] args) {
Team t1 = new Team("CSK", 8, 2);
Team t2 = new Team("RCB", 1, 9);
Team t3 = new Team("SRH", 7, 3);
Team t4 = new Team("GT", 6, 4);
Team t5 = new Team("RR", 5, 5);
PriorityQueue<Team> p = new PriorityQueue<>(Comparator.comparing(Team::getWL).reversed());
p.add(t1);
p.add(t2);
p.add(t3);
p.add(t4);
p.add(t5);
Team x = p.poll(); // CSK
Team y = p.poll(); // SRH
System.out.println(x.name);
System.out.println(y.name);
// System.out.println((p.poll()).name);
}
}