-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoreCard.java
More file actions
33 lines (27 loc) · 942 Bytes
/
scoreCard.java
File metadata and controls
33 lines (27 loc) · 942 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
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
class scoreCard{
Map<String,Integer> stu= new TreeMap<>();
public void addStudent(String name,int marks){
stu.put(name,stu.getOrDefault(name, 0)+marks);
}
public void printScore(){
stu.entrySet()
.stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.forEach(e->System.out.println(e.getKey()+":"+e.getValue()));
// stu.stream().sorted()
//stu.stream.sorted(Map.Entry.comparingByKey);
}
public static void main(String args[]){
scoreCard sc=new scoreCard();
sc.addStudent("One", 67);
sc.addStudent("Two", 71);
sc.addStudent("Third",61);
sc.addStudent("AA",61);
sc.addStudent("One", 10);
sc.addStudent("Third",15);
sc.printScore();
}
}