Computer Science, asked by tae301295, 5 days ago

Write java program by taking input as student name, roll number, marks of four subjects and section of student. Assuming that the exam is conducted for 100 marks. Find out the percentage and grade.

Percentage Grade

> = 80 to 100 Excellent


> = 70 to <80 First Div.


> = 60 to <70 Second Div.


> = 50 to <60 Third Div.


Less than 50 Fail


print the output in following format:


Student name Roll no. Percentage Grade

__________ _____ ________ _____

XX XX XX XX


" WRITE INPUT, OUTPUT AND VARIABLE DESCRIPTION TABLE " ​

Answers

Answered by Shivu516
13

Hope it helps (. ❛ ᴗ ❛.)

Please mark my answer as Brainliest, I tried to make it perfect.

I have not added all the possible outputs because it would make the answer even lengthier but I have tested all the possible outputs.  

I have changed the format of output a little in order to make it a bit more organised

import java.util.Scanner;

public class Grade_Teller{

   public static void main(String [] args){

       Scanner sc = new Scanner(System.in);

       double m1, m2, m3 , m4, per = 0;

       System.out.print("Enter the name: ");

       String name = sc.nextLine();

       System.out.print("Enter the class: ");

       String Class = sc.nextLine();

       System.out.print("Enter the Roll Number: ");

       int rln = sc.nextInt();

       System.out.println("Enter the marks out of 100");

       System.out.print("Enter the marks in the first subject: ");

       m1 = sc.nextDouble();

       System.out.print("Enter the marks in the second subject: ");

       m2 = sc.nextDouble();

       System.out.print("Enter the marks in the third subject: ");

       m3 = sc.nextDouble();

       System.out.print("Enter the marks in the fourth subject: ");

       m4 = sc.nextDouble();

       if ((m1 + m2 + m3 + m4) <= 400){

           per = (m1 + m2 + m3 + m4)/400 * 100;

           System.out.println("");

           System.out.println("Name: " + name);

           System.out.println("Class: " + Class);

           System.out.println("Roll Number: " + rln);

           System.out.println("Percentage: " + per);  

           if (per >= 80)

           System.out.println("Grade: " + "Excellent!!");

           else if (per >= 70)

           System.out.println("Grade: " + "First Division");

           else if (per >= 60)

           System.out.println("Grade: " + "Second Division");

           else if (per >= 50)

           System.out.println("Grade: " + "Third Division");

           else  

           //System.out.print("Grade: " + "Padai Likhai Karp IS-YS Bano Aur Desh Ko Sambhalo");

           System.out.println("Grade: " + "Failed :(");

       }

       else  

       System.out.println("The entered marks cannot be more than 100");

   }

}

Output:

Enter the name: Shivansh Gupta

Enter the class: 9th A

Enter the Roll Number: 43

Enter the marks out of 100

Enter the marks in the first subject: 93

Enter the marks in the second subject: 99

Enter the marks in the third subject: 98

Enter the marks in the fourth subject: 88

Name: Shivansh Gupta

Class: 9th A

Roll Number: 43

Percentage: 94.5

Grade: Excellent!!

Attachments:
Answered by Anonymous
30

import java.util.Scanner;   // Importing java.util package

public class StudentReport  // Creating class

{

   // The main function

   public static void main(String args[]) {

       // Creating object of scanner class

       Scanner scr = new Scanner(System.in);

       // Taking user input to accept the name of the student and storing it in string data type

       System.out.print("Enter name of student: ");

       String n = scr.nextLine();

       // Taking user input to accept the class of student and storing it in int data type

       System.out.print("Enter class of student: ");

       int c = scr.nextInt();

       // Taking user input to accept the roll no. of student and storing it in int data type

       System.out.print("Enter roll number of student: ");

       int r = scr.nextInt();

       // Taking user input to accept the marks in 1st subject and storing it in int data type

       System.out.print("Enter marks in 1st subject: ");

       int m1 = scr.nextInt();

       // Taking user input to accept the marks in 2nd subject and storing it in int data type

       System.out.print("Enter marks in 2nd subject: ");

       int m2 = scr.nextInt();

       // Taking user input to accept the marks in 3rd subject and storing it in int data type

       System.out.print("Enter marks in 3rd subject: ");

       int m3 = scr.nextInt();

       // Taking user input to accept the marks in 4th subject and storing it in int data type

       System.out.print("Enter marks in 4th subject: ");

       int m4 = scr.nextInt();

       if (m1 + m2 + m3 + m4 <= 400) {

           // Calculating percentage obtained by the student

           double Percentage = (m1 + m2 + m3 + m4)/400.0 * 100.0;

           // Stroring grade as string data type

           String grade;

           if (Percentage >= 90) {

               grade = "Excellent.";

           }

           else if (Percentage >= 70) {

               grade = "First Division.";

           }

           else if (Percentage >= 60) {

               grade = "Second Division.";

           }

           else if (Percentage >= 50) {

               grade = "Third Division.";

           }

           else {

               grade = "Fail.";

           }

           System.out.println("");

           // Displaying the name of student

           System.out.println("Student name: " + n);

           // Displaying the name of student

           System.out.println("Class: " + c);

           // Displaying the name of student

           System.out.println("Roll number: " + r);            

           // Displaying the percentage obtained by the student

           System.out.println("Percentage: " + Percentage);

           // Displaying the grade of student

           System.out.println("Grade: " + grade);

       }

   }

}

Output:

Enter name of student: Eldarion

Enter class of student: 12

Enter roll no of student: 5

Enter marks in 1st subject: 98

Enter marks in 2nd subject: 87

Enter marks in 3rd subject: 91

Enter marks in 4th subject: 89

Student name: Eldarion

Class 12

Roll number: 5

Percentage: 91.25

Grade: Excellent.

Similar questions