Difference between revisions of "Letter Grade Conversion"
(added code credit to Josh Simard) |
m (Changed to codeblocks) |
||
Line 16: | Line 16: | ||
|Solution= | |Solution= | ||
First, figure out which constants need to be declared. Remember that declaring constants guarantee that these values will not change. | First, figure out which constants need to be declared. Remember that declaring constants guarantee that these values will not change. | ||
− | + | {{CodeBlock|Code= | |
final int MAX_GRADE = 100; | final int MAX_GRADE = 100; | ||
Line 23: | Line 23: | ||
final int MIN_C = 60; | final int MIN_C = 60; | ||
final int MIN_D = 50; | final int MIN_D = 50; | ||
− | final int MIN_F = 0; | + | final int MIN_F = 0; |
− | + | }} | |
− | + | ||
Hint: This program uses Scanner for input. Remember to import the Scanner code. | Hint: This program uses Scanner for input. Remember to import the Scanner code. | ||
− | + | {{CodeBlock|Code= | |
import java.util.Scanner; | import java.util.Scanner; | ||
− | + | }} | |
Revision as of 15:08, 4 December 2011
Back to the Program-A-Day homepage
ProblemCreate a program that converts a numerical grade to its corresponding letter grade. The letter grades that need assigning are (Please note that the following ranges are inclusive):
|
...by studentsThis problem was part of the midterm I wrote when I was in COMP 1010 (which was known as 74.101 when I took it). The problem was in the form of a multiple choice question, and asked what letter grade would be generated in the provided code. I was confident in my answer, but later found out that I was wrong. I made the mistake of assuming what the code would generate, instead of actually mapping out the answer. When doing if statements, I learned to test variables and evaluate them using the provided conditions, instead of assuming that the solution in my head is what the program actually does. | |
---|---|---|
SolutionFirst, figure out which constants need to be declared. Remember that declaring constants guarantee that these values will not change. final int MAX_GRADE = 100; final int MIN_A = 80; final int MIN_B = 70; final int MIN_C = 60; final int MIN_D = 50; final int MIN_F = 0; Hint: This program uses Scanner for input. Remember to import the Scanner code. import java.util.Scanner; | ||
Code |