Saturday 7 January 2017

Student Record Management System in JAVA

This Student Record Management System is a simple JAVA Project without Object Oriented Programming. It is supposed to give knowledge to beginners about basic JAVA Functionalities.

Code:

import java.io.*;
import java.util.*;

public class Pro
{
    public static int rn,contact,sem;
    public static double cgpa;
    public static String name,fname,email,pro,grade,dob;
    public static void main(String args[])
    {
    int a;
    char ch;
    do
    {
    Scanner s=new Scanner(System.in);
       System.out.print("*************************************\n*                                    *\n*  WELLCOME TO STUDENT RECORD SYSTEM *\n*");
       System.out.println("                                    *");
       System.out.println("*************************************\n\n");
           System.out.println("\t1.Enter student Record");
           System.out.println("\t2.Append student Record");
           System.out.println("\t3.List Student Record");
           System.out.println("\t4.Modify Student Record");
           System.out.println("\t5.Delete Student Record");
           System.out.println("\t6.Search Student Record");
           System.out.println("\t<<<<<<<<<<>>>>>>>>>>>>\n");
           System.out.print("\t=====================\n \t  Enter your Choice : ");
           a=s.nextInt();
           switch(a)
           {
             case 1:
              enter();
               break;
               case 2:
               append();
               break;
               case 3:
               list();
               break;
            case 4:
               modify();
               break;
               case 5:
               delete();
               break;
            case 6:
            search();
            break;
            default:
            System.out.println("Invalid Choice");
           }
           System.out.println("More Actions ? (Y/N) : ");
            String b=s.next();
            ch=b.charAt(0);
           
    }
            while((ch=='y' || ch=='Y'));
            System.out.print("End Of Project");
    }
    static void enter()
    {
    Scanner s=new Scanner(System.in);
    try
    {
       FileOutputStream fos=new FileOutputStream("Stu.data",true);
            DataOutputStream dos=new DataOutputStream(fos);
       System.out.println("Personal Record of Student");
       System.out.println("Please enter roll number of Student");
       rn=s.nextInt();
       System.out.println("Enter the name of Student");
       name=s.next();
       System.out.println("Enter Father's name of student");
       fname=s.next();
       System.out.println("Enter Date of Birth of student");
       dob=s.next();
       System.out.println("Enter contact number");
       contact=s.nextInt();
       System.out.println("Enter the Email");
       email=s.next();
       System.out.println("Academic Record Of Student");
       System.out.println("Enter Program of student");
       pro=s.next();
       System.out.println("Enter semester of student");
       sem=s.nextInt();
       System.out.println("Enter cgpa of student");
       cgpa=s.nextDouble();
       System.out.println("Enter grade of student");
       grade=s.next();
            dos.writeInt(rn);
            dos.writeUTF(name);
            dos.writeUTF(fname);
            dos.writeUTF(dob);
            dos.writeInt(contact);
            dos.writeUTF(email);
            dos.writeUTF(pro);
            dos.writeInt(sem);
            dos.writeDouble(cgpa);
            dos.writeUTF(grade);
        }
        catch(Exception e1)
        {
            System.out.print("Invalid input !!");
        }
    }
    static void append()
    {
    int n;
    System.out.print("Enter number of students");
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
        try
        {
            FileOutputStream fos=new FileOutputStream("Stu.data",true);
            DataOutputStream dos=new DataOutputStream(fos);
            for(int i=0;i<n;i++)
            {
                System.out.println("Personal Record of Student");
           System.out.println("Please enter roll number of Student");
           rn=s.nextInt();
           System.out.println("Enter the name of Student");
           name=s.next();
           System.out.println("Enter Father's name of student");
             fname=s.next();
           System.out.println("Enter Date of Birth of student");
           dob=s.next();
           System.out.println("Enter contact number");
           contact=s.nextInt();
           System.out.println("Enter the Email");
           email=s.next();
           System.out.println("Academic Record Of Student");
           System.out.println("Enter Program of student");
           pro=s.next();
           System.out.println("Enter semester of student");
              sem=s.nextInt();
           System.out.println("Enter cgpa of student");
           cgpa=s.nextDouble();
           System.out.println("Enter grade of student");
           grade=s.next();
                dos.writeInt(rn);
                dos.writeUTF(name);
                dos.writeUTF(fname);
                dos.writeUTF(dob);
                dos.writeInt(contact);
                dos.writeUTF(email);
                dos.writeUTF(pro);
                dos.writeInt(sem);
                dos.writeDouble(cgpa);
                dos.writeUTF(grade);
            }
        }
        catch(Exception e2)
        {
            System.out.print("Invalid input !!!");
        }
     }
     static void list()
     {
    try
    {
       FileInputStream fis=new FileInputStream("Stu.Data");
       DataInputStream dis=new DataInputStream(fis);
       while(true)
       {
        rn=dis.readInt();
       name=dis.readUTF();
       fname=dis.readUTF();
       dob=dis.readUTF();
       contact=dis.readInt();
       email=dis.readUTF();
       pro=dis.readUTF();
       sem=dis.readInt();
       cgpa=dis.readDouble();
       grade=dis.readUTF();
       System.out.println("\n");
       System.out.println("Personal Record Of Student");
       System.out.println("Student Roll number : "+rn);
       System.out.println("Student Name : "+name);
       System.out.println("Student Father Name : "+fname);
       System.out.println("Student Date of Birth : "+dob);
       System.out.println("Student contact number : "+contact);
       System.out.println("Email : "+email);
       System.out.println("Academic Record Of Student");
       System.out.println("Program of Student : "+pro);
       System.out.println("Semester of Student : "+sem);
       System.out.println("CGPA : "+cgpa);
       System.out.println("Grade of Student : "+grade);
       }
    }
    catch(Exception e3)
    {
    System.out.println("End Of File");
    }
     }
       static void modify()
     {
      char ch;
      int rollnum,numofrec=0;
    try
    {
            FileInputStream fis=new FileInputStream("Stu.Data");
       DataInputStream dis=new DataInputStream(fis);
       Scanner s=new Scanner(System.in);
       System.out.print("Enter the student roll number to modify : ");
            rollnum=s.nextInt();
       while(true)
       {
        rn=dis.readInt();
                name=dis.readUTF();
           fname=dis.readUTF();
           dob=dis.readUTF();
                contact=dis.readInt();
                email=dis.readUTF();
                pro=dis.readUTF();
                sem=dis.readInt();
                cgpa=dis.readDouble();
                grade=dis.readUTF();
              numofrec++;
              if(rn==rollnum)
                {
                    System.out.println("Personal Record Of Student");
           System.out.println("Student Roll number : "+rn);
               System.out.println("Student Name : "+name);
               System.out.println("Student Father Name : "+fname);
               System.out.println("Student Date of Birth : "+dob);
               System.out.println("Student contact number : "+contact);
               System.out.println("Email : "+email);
               System.out.println("Academic Record Of Student");
               System.out.println("Program of Student : "+pro);
               System.out.println("Semester of Student : "+sem);
               System.out.println("CGPA : "+cgpa);
                    System.out.println("Grade of Student : "+grade);
               System.out.println("Do you want to modify this record ? (Y/N) : ");
               String b=s.next();
               ch=b.charAt(0);
               if(ch=='y' || ch=='Y')
             {
              try
                     {
                      FileOutputStream fos=new FileOutputStream("Stu.data",true);
                           DataOutputStream dos=new DataOutputStream(fos);
                   System.out.println("Personal Record of Student");
                   System.out.println("Please enter roll number of Student");
                   rn=s.nextInt();
                            System.out.println("Enter the name of Student");
                            name=s.next();
                       System.out.println("Enter Father's name of student");
                       fname=s.next();
                       System.out.println("Enter Date of Birth of student");
                       dob=s.next();
                       System.out.println("Enter contact number");
                       contact=s.nextInt();
                       System.out.println("Enter the Email");
                       email=s.next();
                       System.out.println("Academic Record Of Student");
                       System.out.println("Enter Program of student");
                       pro=s.next();
                       System.out.println("Enter semester of student");
                       sem=s.nextInt();
                            System.out.println("Enter cgpa of student");
                            cgpa=s.nextDouble();
                            System.out.println("Enter grade of student");
                       grade=s.next();
                            dos.writeInt(rn);
                            dos.writeUTF(name);
                            dos.writeUTF(fname);
                            dos.writeUTF(dob);
                            dos.writeInt(contact);
                            dos.writeUTF(email);
                            dos.writeUTF(pro);
                            dos.writeInt(sem);
                            dos.writeDouble(cgpa);
                            dos.writeUTF(grade);
                            System.out.println("Record Modified");
                   }
               catch(Exception e4)
               {
                System.out.println("End Of File");
               }
            }
           else
            System.out.println("No modifications were made");
                }
       }
                       
    }
      catch(Exception e5)
      {
      System.out.println("End Of File");
      }
     }
     static void delete()
     {
      String fileName = "Stu.data";
      File f = new File(fileName);
      if (f.exists())
      System.out.println("Deleted "+fileName);
      if (!f.canWrite())
      System.out.println("Delete "+fileName);
      if (f.isDirectory())
        {
        String[] files = f.list();
        if (files.length > 0)
        System.out.println("deleted "+fileName);
        }
        boolean success = f.delete();
        if (!success)
        System.out.println("deletion failed");
     }
      static void search()
      {
      int rolnum,ss;
         String sname;
         Scanner s=new Scanner(System.in);
         System.out.println("1.Search by Name");
         System.out.println("2.Search by student roll number");
         System.out.println("Enter choice : ");
         ss=s.nextInt();
         switch(ss)
         {
          case 1:
          try
       {
        System.out.println("Enter student name to search");
                sname=s.next();
           FileInputStream fis=new FileInputStream("Stu.Data");
           DataInputStream dis=new DataInputStream(fis);
       while(true)
       {
        rn=dis.readInt();
             name=dis.readUTF();
           fname=dis.readUTF();
           dob=dis.readUTF();
               contact=dis.readInt();
           email=dis.readUTF();
           pro=dis.readUTF();
           sem=dis.readInt();
               cgpa=dis.readDouble();
           grade=dis.readUTF();
           if(name==sname)
           {
               System.out.println("Personal Record Of Student");
               System.out.println("Student Name : "+name);
           System.out.println("Student Father Name : "+fname);
               System.out.println("Student Date of Birth : "+dob);
           System.out.println("Student contact number : "+contact);
             System.out.println("Email : "+email);
           System.out.println("Academic Record Of Student");
       System.out.println("Program of Student : "+pro);
       System.out.println("Semester of Student : "+sem);
       System.out.println("CGPA : "+cgpa);
       System.out.println("Grade of Student : "+grade);
           }
       }
    }
       catch(Exception e6)
       {
          System.out.println("End Of File");
       }
       break;
    case 2:
       try
       {
          FileInputStream fis=new FileInputStream("Stu.Data");
           DataInputStream dis=new DataInputStream(fis);
         System.out.println("Enter student roll number to search");
         rolnum=s.nextInt();
         while(true)
                {
                rn=dis.readInt();
             name=dis.readUTF();
             fname=dis.readUTF();
             dob=dis.readUTF();
             contact=dis.readInt();
             email=dis.readUTF();
             pro=dis.readUTF();
             sem=dis.readInt();
             cgpa=dis.readDouble();
             grade=dis.readUTF();
             if(rn==rolnum)
             {
              System.out.println("Personal Record Of Student");
       System.out.println("Student Name : "+name);
       System.out.println("Student Father Name : "+fname);
               System.out.println("Student Date of Birth : "+dob);
                 System.out.println("Student contact number : "+contact);
       System.out.println("Email : "+email);
       System.out.println("Academic Record Of Student");
           System.out.println("Program of Student : "+pro);
       System.out.println("Semester of Student : "+sem);
       System.out.println("CGPA : "+cgpa);
       System.out.println("Grade of Student : "+grade);
           }
       }
          }
         catch(Exception e7)
         {
            System.out.println("End Of File");
         }
         break;
      }
     }
}

Output:


No comments:

Post a Comment