Software & Finance





Java Simple Student Mark List Preparation





Here is Java source code for simple Mark List Preparation . You can add student name and marks for 5 subjects. Then you can view the student mark list.

 

This Program is a simple version and will not persist any data and you can not modify any data. To get the advanced version which does menu oriented persistant data, view the following links:

 

See Also:

 

Source Code


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");

            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.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;

}

 

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;

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

                  stud.total += stud.marks[i];

            m_studList[m_nMaxStudents++] = stud;

            return 1;

      }

}

 

Output


Welcome to Student MarkList Application

Enter the number of Students: 3

 

 

Enter the 1 student information:

Student Name: AAA

Sub 1 Mark:40

Sub 2 Mark:50

Sub 3 Mark:60

Sub 4 Mark:70

Sub 5 Mark:80

 

 

Enter the 2 student information:

Student Name: BBB

Sub 1 Mark:80

Sub 2 Mark:80

Sub 3 Mark:70

Sub 4 Mark:670

Sub 5 Mark:90

 

 

Enter the 3 student information:

Student Name: CCC

Sub 1 Mark:100

Sub 2 Mark:90

Sub 3 Mark:99

Sub 4 Mark:88

Sub 5 Mark:89

_______________________________________________________________

SNo Student Name       Sub1   Sub2   Sub3   Sub4   Sub5   Total

_______________________________________________________________

  1 AAA                 40     50     60     70     80     300

  2 BBB                 80     80     70     670    90     990

  3 CCC                 100    90     99     88     89     466

_______________________________________________________________