3)Write a java program which creates class Student (Rollno, Name,- Number of subjects,Marks of each subject)(Number of subjects varies for each student) Write a parameterized constructor which initializes roll no, name & Number of subjects and create the array of marks dynamically. Display the details of all students with percentage and class obtained.


import java.io.*;
class Student
{
int rollno;
String name;
int number_of_subjects;
int mark[];

Student(int roll,String stud_name,int noofsub)throws IOException
{
rollno=roll;
name=stud_name;
number_of_subjects= noofsub;
getMarks(noofsub);
}
public void getMarks(int nosub ) throws IOException
{
mark=new int[nosub];
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
for (int i=0; i<nosub;i++)
{
System.out.println(“Enter “+i+”Subject Marks.:=> “);
mark[i]=Integer.parseInt(br.readLine());
System.out.println(“”);
}

}
public void calculateMarks()
{
double percentage=0;
String grade;
int tmarks=0;
for (int i=0;i<mark.length;i++)
{
tmarks+=mark[i];
}
percentage=tmarks/number_of_subjects;
System.out.println(“Roll Number :=> “+rollno);
System.out.println(“Name Of Student is :=> “+name);
System.out.println(“Number Of Subject :=> “+number_of_subjects);
System.out.println(“Percentage Is :=> “+percentage);

if (percentage>=70)
System.out.println(“Grade Is First Class With Distinction “);
else if(percentage>=60 && percentage<70)
System.out.println(“Grade Is First Class”);
else if(percentage>=50 && percentage<60)
System.out.println(“Grade Is Second Class”);
else if(percentage>=40 && percentage<50)
System.out.println(“Grade Is Pass Class”);
else
System.out.println(“You Are Fail”);
}
}
class StudentDemo
{
public static void main(String args[])throws IOException
{
int rno,no,nostud;
String name;
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
System.out.println(“Enter How many Students:=> “);
nostud=Integer.parseInt(br.readLine());
Student s[]=new Student[nostud];

for(int i=0;i<nostud;i++)
{
System.out.println(“Enter Roll Number:=> “);
rno=Integer.parseInt(br.readLine());
System.out.println(“Enter Name:=> “);
name=br.readLine();
System.out.println(“Enter No of Subject:=> “);
no=Integer.parseInt(br.readLine());
s[i]=new Student(rno,name,no);
}
for(int i=0;i<nostud;i++)
{
s[i].calculateMarks();
}

}
}

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