Java Programming | Grade System for marks

Introduction

This is tutorial for grade system of marks in java. The program takes the marks from the user and calculates the percentage and prints it along with grade. The program is extendable. Go enjoy the program. Lets begin……….

Program for grade system for marks.

//import Scanner as we require it.
import java.util.Scanner;

// the name of our class its public
public class GradeSystem {
	//void main
		public static void main (String[] args)
		{
			//declare int and float
			int a,b,c,tot;
			float per;

			//Declare input as scanner
			Scanner input = new Scanner(System.in);

			//Take inputs
			 System.out.println("Enter marks of physics:");
			 a = input.nextInt();
			 System.out.println("Enter marks of chemistry:");
			 b = input.nextInt();
			 System.out.println("Enter marks of maths:");
		     c = input.nextInt();

		     //calculate
		     tot = a + b + c;
		     per = tot/3;
			//print the Percentage and grade
			System.out.println("Percentage = "+per);

			if(per>90)
			System.out.println("Grade : A");
			else
			{
				if(per>70)
					System.out.println("Grade : B");
				else
				{
					if(per>50)
						System.out.println("Grade : C");
					else
						System.out.println("Grade : D");
				}
			}
		}
}

Output

Enter marks of physics:
99
Enter marks of chemistry:
98
Enter marks of maths:
67
Percentage = 88.0
Grade : B

How it works

  1. The program prints the message to enter marks.
  2. The user enters marks.
  3. The percentage is calculated.
  4. If-else statement decides the grade and prints it.

Extending it

The program can be extended by using more marks and more grades. Go extend it.

Explanation.

  1. Import the Scanner.
  2. Declare the class as public
  3. Add the void main function
  4. Add system.out.println() function with the message to enter marks.
  5. Declare input as Scanner.
  6. Take the inputs and save it in variables.
  7. Calculate percentage and save it in variable.
  8. Add a if-else statement to find the grade according to percentage.
  9. Add system.out.println() function to print the grade and percentage.

At the end.

You learnt creating the Java program for Grade System for marks. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s