/*
* Computer Science Project on result
Class : Result
Member Variables:
rollno, Name, ,avg ,grade, array of marks in 5 subjects
Functions used :
Default constructor
Parameterized constructor
void new_student( int , String, int, int , int, int, int) // Function to accept rollno, name, eng, maths, science, art, geo marks from user.
void display_details( )// Function to display the details
void calcavg() // to calculate the average marks and store in avg
void calcgrade()// to calculate the grade using the following formula
avg grade
>90 A
>70 &<= 90 B
>60 & <=70 C
>40 & <=60 D
<40 F
double return_average( ) // To return the average marks
String return_name()//To return the name
char return_grade( ) // To return the grade
Class Useresult
Write a main method which creates an object of the above class and call all the methods
*/
import java.io.*;
class useresult
{
public static void main(String args[])throws IOException
{
result ob=new result(); //automatically calls default constructor
int mks[]={89,99,90,88,78};
result ob1=new result(007,"John",mks); //automatically calls parameterized constructor
ob.new_student(1001, "Robin", 90, 98,95,90,96);
ob.display_details();
ob.calcavg();
ob.calcgrade();
System.out.println("\n**********FINAL RESULT**********");
System.out.println("NAME \t AVERAGE \t GRADE ");
System.out.println(ob.return_name()+"\t "+ob.return_average()+"\t "+ob.return_grade());
}
}
class result
{
int rollno;
String name;
double avg;
char grade;
int marks[]=new int[5];
int i;
result()
{
rollno=0;
name="";
marks[0]=0;
marks[1]=0;
marks[2]=0;
marks[3]=0;
marks[4]=0;
}
result(int rn, String n, int m[])
{
rollno=rn;
name=n;
for(i=0;i<5;i++)
{
marks[i]=m[i];
}
}
void new_student(int r, String stu_name, int eng, int maths, int sci, int arts, int geo)
{
rollno=r;
name=stu_name;
marks[0]=eng;
marks[1]=maths;
marks[2]=sci;
marks[3]=arts;
marks[4]=geo;
}
void display_details()
{
System.out.println("ROLL NO\tNAME \tENG\tMATHS\tSCI\tARTS\tGEO");
System.out.println(+rollno+"\t"+name+"\t"+marks[0]+"\t "+marks[1]+"\t "+marks[2]+"\t "+marks[3]+"\t "+marks[4]);
}
void calcavg()
{
int sum=0;
for(i=0;i<5;i++)
{
sum=sum+marks[i];
}
avg=sum/5;
}
void calcgrade()
{
if(avg>90)
{
grade='A';
}
else if(avg>70 && avg<=90)
{
grade='B';
}
else if(avg>60 && avg<=70)
{
grade='C';
}
else if(avg>40 && avg<=60)
{
grade='D';
}
else
{
grade='F';
}
}
double return_average()
{
return avg;
}
String return_name()
{
return name;
}
char return_grade()
{
return grade;
}
}
/*
*
*
OUTPUT:
ROLL NO NAME ENG MATHS SCI ARTS GEO
1001 Robin 90 98 95 90 96
**********FINAL RESULT**********
NAME AVERAGE GRADE
Robin 93.0 A
*/