Advertisement
thotfrnk

grades ver1.java

Mar 26th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1.  
  2. import java.util.Scanner; //importing scanner
  3. public class grades { //program begins
  4.     public static void main(String[] args) { //main method begins
  5.  
  6.         Scanner input = new Scanner (System.in); //scanner declaration
  7.  
  8.         //variable declaration
  9.         int mark;
  10.  
  11.         //for the user to input the student's grade
  12.         System.out.println("Please enter the student's mark: ");
  13.         mark = input.nextInt();
  14.  
  15.         //calls on method letterGrade and outputs the student's grade based on the mark they got
  16.         System.out.println("Student's Grade: " +letterGrade(mark));
  17.     } //main method ends
  18.  
  19.     //method called letterGrade, it goes through a series of if statements to assign the correct grade to the mark a student receives
  20.     //if the mark isn't valid, an error statement will be shown
  21.     public static String letterGrade(int marks) {
  22.        //variable declaration
  23.         String grade = null;
  24.  
  25.         //if statements to assign the letter grade to the mark a student gets
  26.         if(marks >= 67 && marks <= 100) {
  27.             grade = "A";
  28.         }
  29.         else
  30.             if(marks >= 60 && marks <= 66) {
  31.                 grade = "B+";
  32.             }
  33.             else
  34.                 if(marks >= 50 && marks <= 59) {
  35.                     grade = "B";
  36.                 }
  37.                 else
  38.                     if(marks >= 43 && marks <= 49) {
  39.                         grade = "C";
  40.                     }
  41.                     else
  42.                         if(marks >= 40 && marks <= 42) {
  43.                             grade = "D";
  44.                         }
  45.                         else
  46.                             if(marks >= 0 && marks <= 39) {
  47.                                 grade = "Fail";
  48.                             }
  49.                             else {
  50.                                 System.out.println("Invalid mark.");
  51.                             } //if statements ends
  52.  
  53.         //return statement to display in the main method
  54.         return grade;
  55.     } //method letterGrade ends
  56. } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement