forked from code-differently/code-differently-24-q1
/
GpaToLetterGradeConverter.java
59 lines (47 loc) · 1.92 KB
/
GpaToLetterGradeConverter.java
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
50
51
52
53
54
55
56
57
58
59
package com.codedifferently.lesson7.gpa;
import com.codedifferently.lesson7.util.LinkedListNode;
/** An object that converts GPAs to their letter grade equivalent. */
public class GpaToLetterGradeConverter {
private LinkedListNode<GpaLetterGradeMapping> head;
public GpaToLetterGradeConverter() {
this.head = new LinkedListNode<GpaLetterGradeMapping>(new GpaLetterGradeMapping(0, 1, "F"));
var current = this.head;
current.next =
new LinkedListNode<GpaLetterGradeMapping>(new GpaLetterGradeMapping(1, 1.3, "D"));
current = current.next;
current.next =
new LinkedListNode<GpaLetterGradeMapping>(new GpaLetterGradeMapping(1.3, 1.7, "D+"));
// TODO(you): Finish configuring the linked list.
}
/**
* Converts a GPA on the 4.0 scale to the corresponding letter grade using the college board
* scale. See
* https://bigfuture.collegeboard.org/plan-for-college/college-basics/how-to-convert-gpa-4.0-scale
* for details.
*
* @param gpa The GPA value.
* @return The letter grade ("A+", "A", "A-", "B+", etc.).
*/
public String convertToLetterGrade(double gpa) throws IllegalArgumentException {
// Iterate through the list list starting at the head node and return the letter grade for the
// matching GPA range.
throw new UnsupportedOperationException();
}
}
/** An object that represents the mapping between a GPA range and a grade letter. */
class GpaLetterGradeMapping {
public double minGpaInclusive;
public double maxGpaExclusive;
public String gradeLetter;
public GpaLetterGradeMapping(double minGpaInclusive, double maxGpaExclusive, String gradeLetter) {
this.minGpaInclusive = minGpaInclusive;
this.maxGpaExclusive = maxGpaExclusive;
this.gradeLetter = gradeLetter;
}
public boolean includesGpa(double gpa) {
throw new UnsupportedOperationException();
}
public String getLetterGrade() {
throw new UnsupportedOperationException();
}
}