-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGradeMapper.go
49 lines (41 loc) · 1.06 KB
/
GradeMapper.go
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
package main
import "strings"
type AbstractCourseGradeMapper interface {
GetCorrespondingGradeGpa(grade *CourseGrade) (float64, float64)
}
type ZcCourseGradeMapper struct {}
func (m *ZcCourseGradeMapper) GetCorrespondingGradeGpa(grade *CourseGrade) (float64, float64) {
weight := float64(grade.Credits)
gradeStr := strings.TrimSpace(grade.Grade)
if gradeStr == "" {
return 0.0, 0.0
}
var letter string
if strings.HasPrefix(gradeStr, "[") && strings.HasSuffix(gradeStr, "]") {
letter = strings.TrimPrefix(strings.TrimSuffix(gradeStr, "]"), "[")
} else {
letter = gradeStr
}
switch letter {
case "A":
return 4.0, weight
case "A-":
return 3.7, weight
case "B+":
return 3.3, weight
case "B":
return 3.0, weight
case "B-":
return 2.7, weight
case "C+":
return 2.3, weight
case "C":
return 2.0, weight
case "C-":
return 1.7, weight
case "F":
return 0.0, weight
default:
return 0.0, 0.0
}
}