Skip to content

Mini Project – Exercise 2

Letter Grade Calculator

  • Project
  • 1 hint
  • 10 of 15 in this chapter

Getting Started

Make a file named GradesFinder and import a scanner into your code.

We want to...

Ask the user to input a number grade. When they input this number grade the code should be able to find out what letter grade they get for their number grade.

  • 100 = perfect score
  • 90-99 = A
  • 80-89 = B
  • 70-79 = C
  • 0-69 = F (failing grade) A sample of the output should look like this.

Hints

Hint 1X

X

Solution

Solution – Exercise 2

Solution

Here is the solution:

Java
import java.util.Scanner;
public class GradesFinder {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter Your Grade: ");
 int grade = input.nextInt();
 if(grade > 100){
 System.out.println("That is impossible, you must have gotten extra points");
 }
 else if(grade == 100){
 System.out.println("You got a perfect score");
 }
 else if(grade>=90){
 System.out.println("You got an A");
 }
 else if(grade>=80){
 System.out.println("You got a B");
 }
 else if(grade>=70){
 System.out.println("You got a C");
 }
 else if(grade>=0){
 System.out.println("You failed, you got an F");
 }
 else{
 System.out.println("You cant get negative points");
 }
 input.close();
 }
}

Give the project a try first.