In an examination, the grades are awarded to the students in 'Science according to the average marks obtained in the examination
Marks
Grades
Distinction
First Division
Second Division
Pass
Promotion not granted
80% and above
60% or more but less than 80%
45% or more but less than 60%
40% or more but less than 45%
Less than 40%
Write a program to input name and marks in Physics, Chemistry and Biology. Calculate the average marks. Display the name, average marks
and the grade obtained.
Answers
import java.util.Scanner;
public class Examination {
static void print(String string) {
System.out.print(string);
}
static String getGrade(float marksAverage) {
if (marksAverage >= 80)
return "Distinction";
else if (marksAverage >= 60)
return "First Division";
else if (marksAverage >= 45)
return "Second Division";
else if (marksAverage >= 40)
return "Pass";
return "Promotion not granted";
}
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
print("Enter your name - ");
String name = sc.nextLine( );
print("Enter Marks of - \n Physics - ");
float marksPhysics = sc.nextFloat( );
print(" Chemistry - ");
float marksChemistry = sc.nextFloat( );
print(" Biology - ");
float marksBiology = sc.nextFloat( );
float marksAverage = (marksPhysics + marksChemistry + marksBiology) / 3f;
System.out.printf("%nName - %s%nAverage marks - %f%nGrade - %s", name, marksAverage, getGrade(marksAverage));
}
}