Posted by: Sourav | December 15, 2013

Student Mark List in a table structure in Java


import java.io.*;

 

 

class MList {

 

      static public CStudents theStudents = new CStudents();

 

static public void ViewRecords()

{

 

      System.out.println(“___________________________________________________________________________”);

      System.out.println(“SNo Student Name       Sub1   Sub2   Sub3   Sub4   Sub5   Total   Average”);

            System.out.println(“___________________________________________________________________________   “);

 

for (int i = 0; i < theStudents.m_nMaxStudents; i++)

{

      System.out.format(“%1$-5d”, i + 1);

      System.out.format(“%1$-19s”, theStudents.m_studList[i].name);

      System.out.format(“%1$-7d”, theStudents.m_studList[i].marks[0]);

      System.out.format(“%1$-7d”, theStudents.m_studList[i].marks[1]);

      System.out.format(“%1$-7d”, theStudents.m_studList[i].marks[2]);

      System.out.format(“%1$-7d”, theStudents.m_studList[i].marks[3]);

      System.out.format(“%1$-7d”, theStudents.m_studList[i].marks[4]);

      System.out.format(“%1$-7d”, theStudents.m_studList[i].total);       System.out.format(“%1$-7d”, theStudents.m_studList[i].average);

      System.out.println();

}

System.out.println(“___________________________________________________________________________”);

}

 

static public void InputRecords()

{

      try

      {

      InputStreamReader input = new InputStreamReader(System.in);

      BufferedReader reader = new BufferedReader(input);

 

      System.out.print(“Student Name: “);

      String name;

      int[] marks = new int[5];

      name = reader.readLine();

 

      for (int i = 1; i <= 5; i++)

      {

            System.out.print(“Sub ” + i + ” Mark: “);

            marks[i – 1] = Integer.parseInt(reader.readLine());

      }

      theStudents.AddRecord(name, marks);

      }

      catch (Exception e)

      {

            e.printStackTrace();

      }

}       

 

 

public static void main(String[] args) {

 

      String inpString = “”;

      InputStreamReader input = new InputStreamReader(System.in);

      BufferedReader reader = new BufferedReader(input);

 

      try

      {

      System.out.print(“Enter the number of students:”);

      inpString = reader.readLine();

      int numStudents = Integer.parseInt(inpString);

 

      for (int i = 1; i <= numStudents; i++)

      {

            System.out.println(“\nEnter ” + i + ” Student Information\n”);

            InputRecords();

      }

      ViewRecords();

      }

      catch (Exception e)

      {

            e.printStackTrace();

      }

    }

}

 

 

class CStudent

{

      public String name;

      public int[] marks = new int[5];

      public int total;       public int average;

}

 

class CStudents

{

      public CStudent[] m_studList = new CStudent[100];

      public int m_nMaxStudents;

 

      public int AddRecord(String name, int[] marks)

      {

            CStudent stud = new CStudent();

            stud.name = name;

            stud.marks = marks;

            stud.total = 0;

            stud.average=0;

            for (int i = 0; i < 5; i++)

                  stud.total += stud.marks[i];             stud.average=stud.total/5;

            m_studList[m_nMaxStudents++] = stud;

            return 1;

      }

}

Advertisements

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

Categories

%d bloggers like this: