Write a class Grade that reads a score (an int) and prints the letter grade:
| Score | Grade |
|---|---|
| 90–100 | A |
| 80–89 | B |
| 70–79 | C |
| 60–69 | D |
| 0–59 | F |
Print it as Grade: B. If the score is below 0 or above 100, print Invalid score instead.
THINK FIRST·CODE LATER
Problem
Write a class Grade that reads a score (an int) and prints the letter grade:
| Score | Grade |
|---|---|
| 90–100 | A |
| 80–89 | B |
| 70–79 | C |
| 60–69 | D |
| 0–59 | F |
Print it as Grade: B. If the score is below 0 or above 100, print Invalid score instead.
Data for this lab
Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.
l6-1-data-1.txt
85
Grade: B
Run your program first, then open this and compare line by line: your output must contain these lines exactly.
Terminal (macOS, Linux, or Windows Command Prompt), after compiling:
java Main < l6-1-data-1.txt
Windows PowerShell does not understand <:
Get-Content l6-1-data-1.txt | java Main
IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.
Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.
Model solution