We can create a Threshold table in the database that has a n:1 relationship with the Course table. This makes the code cleaner and DRYer. It also makes it possible to add courses with more or less letter grades than the ones specified in the code.
My proposal would be for the Threshold table to have the following attributes: (id: int, name: varchar, threshold: double, course_id: int, grade: double). Most of these are self explanatory, but the grade column is for the number that gets used to calculate GPA.
The following SQL could be used for a lookup:
SELECT grade FROM Threshold WHERE course_id = ? AND threshold <= ? ORDER BY grade DESC LIMIT 1
We can create a Threshold table in the database that has a n:1 relationship with the Course table. This makes the code cleaner and DRYer. It also makes it possible to add courses with more or less letter grades than the ones specified in the code.
My proposal would be for the Threshold table to have the following attributes:
(id: int, name: varchar, threshold: double, course_id: int, grade: double). Most of these are self explanatory, but thegradecolumn is for the number that gets used to calculate GPA.The following SQL could be used for a lookup:
SELECT grade FROM Threshold WHERE course_id = ? AND threshold <= ? ORDER BY grade DESC LIMIT 1