Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String gradeBy(int grade) {
- TreeMap<Boolean, Grade> grades = new TreeMap<>();
- grades.put(grade <= 50, Grade.F);
- grades.put(grade >= 51 && grade <= 60, Grade.D);
- grades.put(grade >= 61 && grade <= 70, Grade.C);
- grades.put(grade >= 71 && grade <= 80, Grade.B);
- grades.put(grade > 80 && grade <= 100, Grade.A);
- for (Map.Entry<Boolean, Grade> currentGrade : grades.entrySet()) {
- if (currentGrade.getKey() != true) {
- continue;
- }
- return currentGrade.getValue().name();
- }
- return "You must have been cheating";
- }
- enum Grade {
- F,
- D,
- C,
- B,
- A
- }
- @Test
- public void gradeBy() throws Exception {
- int[] grades = {45, 52, 66, 93, 102};
- for(int grade : grades) {
- String gradeString = this.grading.gradeBy(grade);
- System.out.println(grade + "gives :"+ gradeString);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement