forked from angiejones/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradeBook.java
More file actions
31 lines (25 loc) · 1.15 KB
/
Copy pathGradeBook.java
File metadata and controls
31 lines (25 loc) · 1.15 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
package exercises.chapter12;
import java.util.Map;
public class GradeBook {
public static void main(String[] args){
Map<String, Integer> gradeBook = TestResults.getOriginalGrades();
Map<String, Integer> test2 = TestResults.getMakeUpGrades();
for(var student : test2.entrySet()){
Integer firstGrade = gradeBook.get(student.getKey());
Integer secondGrade = test2.get(student.getKey());
if(secondGrade > firstGrade){
gradeBook.put(student.getKey(), secondGrade);
}
}
/*
The forEach is used here to demonstrate another approach to looping.
However, in reality, I would have added a print statement inside of
the loop above so that the program does not have to loop over this map
for a second time. This would be a more efficient approach:
System.out.println("Student: " + student.getKey() + ", Grade:" + gradeBook.get(student.getKey()));
*/
System.out.println("Final Grades:");
gradeBook.forEach(
(k,v)->System.out.println("Student: " + k + ", Grade: " + v));
}
}