STUDENT DETAILS USING ARRAY OF OBJECTS

AIM:
            To write a program to display student details using inheritance.

ALGORITHM :
Step 1: Start the program.
Step 2: Define the details of the class.
Step 3: Declare all the necessary variables.
Step 4: Declare a class to take the personal detail of the student and to print them.
Step 5: Declare another class Acade which inherits the student class using the
             keyword extends.
Step 6: Call the member function of the students class inside the Acade class 
             using the keyword super.
Step 7: In the main class declare an object of Acade class so as to
             call function which is also called super class function.
Step 8: Compile and execute the program.
Step 9: Stop the program.










SOURCE CODE:
/*student details array of objects*/
import java.io.*;
class studentdetails
{
            String name,regno,branch,address,gender;
            int hostelfee,semfee;
             void getdata() throws IOException
             {
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        System.out.println("Enter the student name:");
                        name=br.readLine();
                        System.out.println("Enter the Reg.NO:");
                        regno=br.readLine();
                        System.out.println("Enter branch");
                        branch=br.readLine();
                        System.out.println("Enter gender M/F:");
                        gender=br.readLine();
                        System.out.println("Enter the address:");
                        address=br.readLine();
                        System.out.println("Enter the semester fees:");
                        semfee=Integer.parseInt(br.readLine());
                        System.out.println("Enter the hostel fee");
                        hostelfee=Integer.parseInt(br.readLine());
            }
            void display()
            {
                        System.out.println("Name:"+name);
                        System.out.println("Regno:"+regno);
                        System.out.println("Gender:"+gender);
                        System.out.println("Address"+address);
                        System.out.println("Total fees:"+(semfee+hostelfee));
            }
}
class Acade extends studentdetails
{
            int total=0;
            float avg;
            int mark[]=new int[5];
            void getdata() throws IOException
            {
                        super.getdata();
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        for(int i=0;i<5;i++)
                        {
                                    System.out.println("Enter the marks:");
                                    mark[i]=Integer.parseInt(br.readLine());
                                    total+=mark[i];
                        }
                        avg=(float)total/5;
            }
            void display()
            {
                        super.display();
                        System.out.println("Student Academic details");
                        for(int i=0;i<5;i++)
                        System.out.println("Subject"+(i)+":"+mark[i]);
                        System.out.println("Total:"+total);
                        System.out.println("Average:"+avg);
            }
}

class students
{
            public static void main(String args[]) throws IOException
            {
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        System.out.println("Enter the no of students:");
                        int n=Integer.parseInt(br.readLine());
                        Acade ac[]=new Acade[n];
                        for(int i=0;i<n;i++)
                        {
                                    ac[i]=new Acade();
                                    ac[i].getdata();
                        }
                        for(int i=0;i<n;i++)
                        ac[i].display();
            }
}


OUTPUT:
Enter the no of students:2
Enter the student name:4Cnotes
Enter the Reg.No:a017
Enter branch:mca
Enter gender M/F:m
Enter the address:trichy
Enter the semester fees:40000
Enter the hostel fee:15000
Enter the marks:98
Enter the marks:89
Enter the marks:78
Enter the marks:89
Enter the marks:90
Enter the student name:vignesh
Enter the Reg.NO:a020
Enter branch:mca
Enter gender M/F:m
Enter the address:covai
Enter the semester fees:40000
Enter the hostel fee:15000
Enter the marks:89
Enter the marks:90
Enter the marks:88
Enter the marks:78
Enter the marks:99

Name:4Cnotes
Regno:a017
Gender:m
Address:trichy
Total fees:55000

Student Academic details
Subject0:98
Subject1:89
Subject2:78
Subject3:89
Subject4:90
Total:444
Average:88.8

Name:vignesh
Regno:a020
Gender:m
Address:covai
Total fees:55000
Student Academic details
Subject0:89
Subject1:90
Subject2:88
Subject3:78
Subject4:99
Total:444
Average:88.8

0 comments: