Java program to calculate and display the student mark result
import java.util.Scanner;
public class Main
{
int roll, sub1, sub2, sub3, total, avg;
String name;
char grade;
Result()
{
name="";
roll=0;
sub1=0;
sub2=0;
sub3=0;
}
Result(int rno1, String name1, int sub11, int sub21, int sub31)
{
roll=rno1;
name=name1;
sub1=sub11;
sub2=sub21;
sub3=sub31;
}
public void grade()
{
total = sub1+sub2+sub3;
avg = total/3;
if(avg>=90&&avg<=100)
grade = 'A';
else if(avg>=80&&avg<90)
grade = 'B';
else if(avg>=70&&avg<80)
grade = 'C';
else if(avg>=60&&avg<70)
grade = 'D';
else if(avg>=50&&avg<60)
grade = 'E';
else
grade = 'F';
}
public void display()
{
System.out.println(" RESULT ");
System.out.println("|____________________________________________________________________________|");
System.out.println("|Roll no.\tName\t\tSub1\tSub2\tsub3\tTotal\tAverage\tGrade|");
System.out.println("|____________________________________________________________________________|");
System.out.println("|"+roll+"\t\t"+name+"\t"+sub1+"\t"+sub2+"\t"+sub3+"\t"+total+"\t"+avg+"\t"+grade+" |");
}
public void getData()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter name: ");
name=sc.next();
System.out.println("Enter roll number: ");
roll=sc.nextInt();
System.out.println("Enter Sub1 marks: ");
sub1=sc.nextInt();
System.out.println("Enter Sub2 marks: ");
sub2=sc.nextInt();
System.out.println("Enter Sub3 marks: ");
sub3=sc.nextInt();
}
public static void main(String[] args)
{
Result obj = new Result();
obj.getData();
obj.grade();
obj.display();
}
}
Comments
Post a Comment