Find grade of a student according to marks in Java

  • admin on February 4, 2019
  • Likes!
Hello friends! Welcome to my website

Today we run java programming to find out the grade of a student when the marks of 6 subjects are given.
The method of assigning grade is –
percentage>=85 grade=A
percentage=70 grade=B
percentage=55 grade=C
percentage=40 grade=D
percentagegrade=E

This java language programming is free all type of errors like the compiler and runtime errors and this programming is tested to compile and then run the program code.
Here is only programming code with the output. This programming output is customized to understand easily.

Find grade of a student according to their percentage in java programming

import java.util.Scanner;

class test2 {
    double m1, m2, m3, m4, m5, m6;
    String grade, name;
    public void Getgrade(double m1,double m2,double m3,double m4,double m5,double m6,String grade,String name) {
        double pre, total;
//total Maarks of all subject
        total = m1 + m2 + m3 + m4 + m5 + m6;
//calculate precentage of marks
        pre = total / 6;
//contdtion to check pass or not
        if (pre > 33) {
// contdtion for grade A
            if (pre >= 85) {
                grade = “A”;
                System.out.println(name+” passed with “+grade+” Grade and “+pre+”%”);
            }
// contdtion for grade B
            else if (pre >= 70) {
                grade = “B”;
                System.out.println(name+” passed with “+grade+” Grade and “+pre+”%”);
            }
// contdtion for grade C
            else if (pre >= 55) {
                grade = “C”;
                System.out.println(name+” passed with “+grade+” Grade and “+pre+”%”);
            }
// contdtion for grade D
            else if (pre >= 40) {
                grade = “D”;
                System.out.println(name+” passed with “+grade+” Grade and “+pre+”%”);
            }
// contdtion for grade E
            else {
                grade = “E”;
                System.out.println(name+” passed with “+grade+” Grade and “+ pre+”%”);
            }
        }
        else {
            System.out.println(name +” is fail in  exam, Score only “+pre+”%”);
        }
    }
}

public class grade {
    public static void main(String[] args) {
        test2 o = new test2();
        Scanner c = new Scanner(System.in);
        System.out.print(“Please Enter the Student Name:”);
        o.name = c.nextLine();
        System.out.print(“enter all the marks of ” + o.name + “: “);
        o.m1 = c.nextInt();
        o.m2 = c.nextInt();
        o.m3 = c.nextInt();
        o.m4 = c.nextInt();
        o.m5 = c.nextInt();
        o.m6 = c.nextInt();
        o.Getgrade(o.m1, o.m2, o.m3, o.m4, o.m5, o.m6, o.grade, o.name);
    }
}


Output:
         Please Enter the Student Name:Abcd
enter all the marks of Abcd: 75
74
45
89
100
99
Abcd passed with B Grade and 80.33333333333333%


I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this Java programming code or input & output please comment below
If you have another question about Java programming send an email by contacting us form are given on the page right side.

Please share your experience about this post,
Thank You!

Article Categories:
Programs in java

Leave a Reply

Your email address will not be published. Required fields are marked *