Reputation: 11
I am brand new to Java (and to programming as a whole) and for my final project in my CS class, I'm making a GPA calculator.
Basically, I would like the user to be able to input his GPA from previous semesters and then his current courses (with the number of credits for each course) and a minimum desired cumulative GPA and the program will print out all of the combinations of possible grades in each course for the current semester that will result in the indicated cumulative GPA.
I haven't started implementing any code yet but I am confused as to the general method to go about the problem. I thought of writing code that runs every single combination of possible grades and then prints out only the ones that result in the desired GPA but that just seems like it would be rather taxing on the computer's processor.
Do you have any ideas of simpler ways to go about creating the combinations of various course grades that result in the user-defined cumulative GPA?
Thank you!
Upvotes: 0
Views: 311
Reputation: 2487
I think a better way to handle this problem is as following.
First, you calculate the minimum GPA required for the current semester to achieve the given goal.
Then, instead of displaying all combinations of current semester's grades for the courses, you could calculate the bare minimum grade combination. Anything above the bare minimum would be considered ok. For example if the minimum for the semester is 2.05, you could say All C's with at least one better grade required
A sample flow might be
1) Initialize all grades to C's. (assuming only passing grades are considered)
2) Check if the GPA > minSemesterGPA. If satisfies, skip to step 4.
3) Increment one of the grades and go back to step 2.
4) Display the combination to the user
Note that, we free ourselves from the course permutations. Only combination of grades are considered therefore making the problem simpler.
Upvotes: 1