Created
August 20, 2017 10:31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GWACalcPresenter(val view: Contract.View, val repo: Contract.Repository) : Contract.Actions{ | |
override fun computeGWA(){ | |
val courses = repo.getAllCourse() | |
val sum = courses.sumByDouble { it.grade * it.units } | |
val totalUnits = courses.sumBy { it.units } | |
var gwa = sum/totalUnits | |
if(gwa.isNaN()) | |
gwa = 0.0 | |
view.updateGWA(gwa) | |
} | |
override fun loadCourses() { | |
val courses = repo.getAllCourse() | |
view.showTable(courses) | |
} | |
override fun onAddCourseClick(course: Course) { | |
view.showInput() | |
} | |
override fun addCourse(course: Course) { | |
repo.addCourse(course) | |
loadCourses() | |
} | |
override fun getCourse(courseCode: String): Course { | |
return repo.getCourse(courseCode) | |
} | |
override fun removeCourse(course: Course) { | |
repo.removeCourse(course) | |
loadCourses() | |
computeGWA() | |
} | |
override fun updateCourse(course: Course) { | |
repo.updateCourse(course) | |
} | |
override fun onChangeGrade(course: Course) { | |
updateCourse(course) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment