Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //importing scanner
- public class grades { //program begins
- public static void main(String[] args) { //main method begins
- Scanner input = new Scanner (System.in); //scanner declaration
- //variable declaration
- int mark;
- //for the user to input the student's grade
- System.out.println("Please enter the student's mark: ");
- mark = input.nextInt();
- //calls on method letterGrade and outputs the student's grade based on the mark they got
- System.out.println("Student's Grade: " +letterGrade(mark));
- } //main method ends
- //method called letterGrade, it goes through a series of if statements to assign the correct grade to the mark a student receives
- //if the mark isn't valid, an error statement will be shown
- public static String letterGrade(int marks) {
- //variable declaration
- String grade = null;
- //if statements to assign the letter grade to the mark a student gets
- if(marks >= 67 && marks <= 100) {
- grade = "A";
- }
- else
- if(marks >= 60 && marks <= 66) {
- grade = "B+";
- }
- else
- if(marks >= 50 && marks <= 59) {
- grade = "B";
- }
- else
- if(marks >= 43 && marks <= 49) {
- grade = "C";
- }
- else
- if(marks >= 40 && marks <= 42) {
- grade = "D";
- }
- else
- if(marks >= 0 && marks <= 39) {
- grade = "Fail";
- }
- else {
- System.out.println("Invalid mark.");
- } //if statements ends
- //return statement to display in the main method
- return grade;
- } //method letterGrade ends
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement