Score Converter – Java Project 1

Score Converter – Java Project 1

First Java project of the semester. Accepts an interger between 0 and 100 and converts it into a letter grade. Ex. Inputting 85 will output “You have earned the letter grade B”. Inputting an integer outside of the range will output “ERROR you have entered an invalid input.”

import java.util.Scanner;

public class ScoreInput {

	public static void main(String[] args) {
		
		Scanner scnr = new Scanner(System.in);
		String errorMessage = "ERROR you have entered an invalid input.";
		char grade;
		int score;
		
		System.out.print("Enter score to evaluate: ");
		score = scnr.nextInt();
		
		if (score < 0 || score > 100) {
			System.out.println(errorMessage);
		} // End of If statement
		else {
			if (score >= 90)
				grade = 'A';
			else if (score >= 80)
				grade = 'B';
			else if (score >= 70)
				grade = 'C';
			else if (score >= 60)
				grade = 'D';
			else
				grade = 'F';
			
			System.out.printf("You have earned the letter grade %c\n", grade);

		} // End of Else statement
	}// End of Main
}//End of Class

Leave a Reply