Wednesday 14 August 2013

// A Simple Java Project to Store and manage Students Records
import java.util.Scanner;
import java.io.*;
class Student1
{
  String name[]=new String[45];
  int roll[]=new int[45];
  String add[]=new String[45];
  String course[]=new String[45];
  long fee_deposit[]= new long[45];
  long dues[]=new long[45];
  long total[]=new long[45];
  long MCA_fee = 500000L;
  long BCA_fee = 300000L;
  long BTech_fee = 500000L;
  long MTech_fee = 300000L;
  long MBA_fee = 300000L;
  int length;
  static int i;
  static int m;
  void length(int ln){ length = ln; }
  
   void Input()
  {
      Scanner sc = new Scanner(System.in);
      //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      for( ; true ; i++)
      {
          System.out.print("Enter Name : ");
          name[i] =  sc.next();
          System.out.print("\nEnter Roll : ");
          roll[i] = sc.nextInt();
          System.out.print("\nEnter Address : ");
          add[i] = sc.next();
          Fee_Structure();
          System.out.print("\nEnter Course : ");
          course[i] = sc.next();
          if(course[i].equalsIgnoreCase("MCA"))
          {
              total[i] = MCA_fee;
              System.out.print("\nFee Structure for MCA is : "+MCA_fee);
              System.out.print("\nEnter Deposited Fee : ");
              fee_deposit[i] = sc.nextLong();
          }
          else if(course[i].equalsIgnoreCase("BCA"))
          {
              total[i] = BCA_fee;
              System.out.print("\nFee Structure For BCA is : "+BCA_fee);
              System.out.print("\nEnter Deposited Fee : ");
              fee_deposit[i] = sc.nextLong();
          }
          else if(course[i].equalsIgnoreCase("BTech"))
          {
              total[i] = BTech_fee;
              System.out.print("\nFee Structure For BTech is : "+BTech_fee);
              System.out.print("\nEnter Deposited Fee : ");
              fee_deposit[i] = sc.nextLong();
          }
          else if(course[i].equalsIgnoreCase("MTech"))
          {
              total[i] = MTech_fee;
              System.out.print("\nFee Structure For MTech is : "+MTech_fee);
              System.out.print("\nEnter Deposited Fee : ");
              fee_deposit[i] = sc.nextLong();
          }
          else if(course[i].equalsIgnoreCase("MBA"))
          {
              total[i] = MBA_fee;
              System.out.print("\nFee Structure For MBA is : "+MBA_fee);
              System.out.print("\nEnter Deposited Fee : ");
              fee_deposit[i] = sc.nextLong();
          }
          System.out.print("\nDo You Want to Insert Another Record Press(Y for Yes/N for No) : ");
          String ch = sc.next();
          if(ch.equalsIgnoreCase("n"))
          break;
      } //for loop closed
      i++;
      length(i);
  }
  void Dues()
  {
     
      for(int j=0; j<length;j++)
      {
          dues[j] = total[j] - fee_deposit[j];
      }
  }
  void Output()
   {
       System.out.println("          ===================================================================");
       System.out.print("                    *********-->> Students Records <<--*********");
       System.out.println("\n          ===================================================================\n");
       System.out.println("_____________________________________________________________________________________");
       System.out.print("Roll\tName\t\tAddress\t\tCourse\tTotal\tFee Deposit\tDues");
       System.out.println("\n_____________________________________________________________________________________\n");
       for(int j=0; j<length; j++)
       {
           System.out.print(roll[j]+"\t");
           System.out.print(name[j]+"\t\t");
           System.out.print(add[j]+"\t\t");
           System.out.print(course[j]+"\t");
           System.out.print(total[j]+"\t");
           System.out.print(fee_deposit[j]+"\t\t");
           System.out.print(dues[j]);
           System.out.println();
       }
       System.out.println("______________________________________________________________________________________\n");
   }
   void Update(int rl)
   {
       Scanner sc = new Scanner(System.in);
       for(int i=0;i<length;i++)
       {
           if(roll[i]==rl)
           {
               System.out.println("What do you want to edit int record Please enter :");
               System.out.println("1 -for Name ");
               System.out.println("2 -for Roll No");
               System.out.println("3 -for Address");
               System.out.println("4 -for Course");
               System.out.println("5 -Fee Deposit ");
               System.out.println("Please enter your Choice :");
               int ch = sc.nextInt();
               switch(ch)
               {
                   case 1:
                      System.out.println("Enter New Name :");
                      name[i] = sc.next();
                      break;
                   case 2:
                      System.out.println("Enter New Roll No :");
                      roll[i] = sc.nextInt();
                      break;
                   case 3:
                      System.out.println("Enter New Address ");
                      add[i] = sc.next();
                      break;
                   case 4:
                      System.out.println("Enter New Course : ");
                      course[i] = sc.next();
                      break;
                   case 5:
                      System.out.println("Enter New Fee deposit : ");
                      fee_deposit[i] = sc.nextLong();
                      break;
               }
           }
        }
   }
   void Search(int key)
   {
      
       int i;     
       for(i=0; i< length; i++)
       {
           if(roll[i] == key)
           {
               System.out.println("Which Field you want to see of Roll No "+key+": " );
               System.out.println("Please Enter :");
               System.out.println(" 1. for Name ");
               System.out.println(" 2. for Address ");
               System.out.println(" 3. for Course ");
               System.out.println(" 4. for Fee Deposit ");
               System.out.println(" 5. for Dues ");
               System.out.println(" 6. for All Fields ");
               Scanner sc = new Scanner(System.in);
               int choice = sc.nextInt();
               switch(choice)
               {
                   case 1 :
                       System.out.print("Name of Roll No. "+key+" is : "+name[i]);
                       break;
                   case 2 :
                       System.out.print("Address of Roll No. "+key+" is :"+add[i]);
                       break;
                   case 3 :
                       System.out.print("Course of Roll No. "+key+" is :"+course[i]);
                       break;
                   case 4 :
                       System.out.print("Fee Deposited by Roll No. "+key+" is : "+fee_deposit[i]);
                       break;
                   case 5 :
                       System.out.print("Dues Of Roll No. "+key+" is : "+dues[i]);
                       break;
                   case 6 :
                       System.out.println("Roll\tName\t\tAddress\t\tCourse\tTotal\tFee Deposit\tDues \n");
                       System.out.print(roll[i]+"\t");
                       System.out.print(name[i]+"\t\t");
                       System.out.print(add[i]+"\t\t");
                       System.out.print(course[i]+"\t");
                       System.out.print(total[i]+"\t");
                       System.out.print(fee_deposit[i]+"\t\t");
                       System.out.print(dues[i]);
                       break;
                       
                   default :
                       System.out.println("This Record Does Not Exists in this Database ");
                       System.out.print("*****Thanks*****");
                       break;
               }
           }
           else
               continue;
       }
      
       if( i > length)
          System.out.println("Record Does Not Exists ");
        
    }
    void Delete(int key)
    {
        int i,j;
        for(i=0; i<length; i++)
        {
           if(roll[i] == key)
           {
               if(i == length-1)
               {
                      roll[i]=0;
                      name[i]=null;
                      add[i]=null;
                      fee_deposit[i]=0;
                      dues[i]=0;   
                   length(length-1);
                   return;
               }
               else
               {for(j=i; j<length-1; j++)
               {
                   roll[j] = roll[j+1];
                   name[j] = name[j+1];
                   add[j] = add[j+1];
                   //total[j] = total[j+1];
                   fee_deposit[j+1] = fee_deposit[j+1];
                   dues[j] = dues[j+1];
                  
               }
                   roll[j]=0;
                      name[j]=null;
                      add[j]=null;
                      fee_deposit[j]=0;
                      dues[j]=0;   
               }
               break;
           }
        }
      length(length-1);this.i--;             
    }
    int LogIn()
    {
       Scanner sc = new Scanner(System.in);
      try{
       FileOutputStream fout1 = new FileOutputStream("USERID.DAT",true);
       FileOutputStream fout2 = new FileOutputStream("PASSWORD.DAT",true);
       DataInputStream dis = new DataInputStream(System.in);
       System.out.println("1 :Have an Acount then @@Press 1 ");
       System.out.println("2 :Create a New Acount @@Press 2 ");
       int choice = sc.nextInt();
       char ch;
       while(true)
       {
        switch(choice)
        {
           case 1:
              FileReader f1 = new FileReader("USERID.DAT");
              FileReader f2 = new FileReader("PASSWORD.DAT");
              BufferedReader fin1 = new BufferedReader(f1);
              BufferedReader fin2 = new BufferedReader(f2);
              System.out.print("Enter User Name :");
              String Id = sc.next();
              System.out.print("\nEnter Password : ");
              String pw = sc.next();
              String text1[]=new String[45];
              String text2[]=new String[45];
              int j = 0;
              int m = 0;
              int i = 0;
              int count;int line_count=0;
              int k = 1;
   
                  if(fin1 == null)
                { 
                        System.out.println("You are Not a Member Please Log in");
                        return 0;
                }
                  while((text1[i++] = fin1.readLine())!=null) {}
             
                  while((text2[m++] = fin2.readLine())!=null) {}
                  for(j=0;j<text1.length;j++)
                  {
                     if(Id.equalsIgnoreCase(text1[j]) && pw.equalsIgnoreCase(text2[j]))
                     {
                       System.out.println("You are Logged In Successfully ");f1.close();f2.close();
                       return 1;
                     }
                     if(f1 == null)
                     { 
                        System.out.println("You are Not a Member Please Log in");
                        return 0;
                     }//m++;
                 }
                 
             // }
             
            
             
                  System.out.println("Your User Id or Password Is Incorrect "+m);
                  return 0;
           case 2 :
              for(int ctr=0; ctr<1 ;ctr++)
              {
                 
                    System.out.print("Enter User Name :");
                      while((ch = (char)dis.read())!= '\n')
                         fout1.write(ch);fout1.close();   
                    System.out.print("\nEnter Password :");
                      while((ch = (char)dis.read())!= '\n')
                         fout2.write(ch);fout2.close();
                  System.out.println("You are Registered Successfully!!Now Log In ");
                  choice = 1;
             
              }
              break;
           default :
              System.out.println("\nWrong Choice :\n");
       }//swtich ended
      }//while ended
      }//try ended
      catch(IOException e){ System.out.println(e);}return 0;
   }
   
   
    void Fee_Structure()
    {
        System.out.println("\n____________Avalable Courses And Their Fee Structures_____________\n");
        System.out.print("_______________________________________________________________________");
        System.out.print("\nCourses  :\tBCA\tMCA\tBTech\tMTech\tMBA");
        System.out.print("\n_______________________________________________________________________");
        System.out.print("\nFees     :\t300000\t500000\t500000\t300000\t30000");
        System.out.print("\n_______________________________________________________________________");
    }
}
class StudentDatabase
{
      public static void main(String args[]) throws IOException
      {
          System.out.println("_______________________________________________________________________________");
          System.out.println("                  STUDENTS DATABASE");
          System.out.println("_______________________________________________________________________________");
          Student1 s = new Student1();
          Scanner sc = new Scanner(System.in);
          System.out.println("Please Log In to Perform Operation");
          while(true)
          {
          int response = s.LogIn();
          if(response == 1)
          {
           while(true)
           {
            
            
                 System.out.println("\n*******Menu********\n");
                 System.out.println("Press......");
                 System.out.println("1 -for Create a Record ");
                 System.out.println("2 -To see the Courses And Fee Structure ");     
                 System.out.println("3 -Edit Record ");
                 System.out.println("4 -for delete a Record ");
                 System.out.println("5 -for Search any Record");
                 System.out.println("6 -for Display Records ");
                 System.out.println("7 -Exit");
                 int ch = sc.nextInt();
              switch(ch)
              {
                case 1 :
                     s.Input();
                     s.Dues();
                     //s.Output();
                     break;
             //to see a particular record in Database
                case 2 :
                     s.Fee_Structure();
                     break;
                case 3 :
                     System.out.println("Enter Roll No for Edit the Record :");
                     int rollNo = sc.nextInt();
                     s.Update(rollNo);
                     s.Dues();
                     break;
                case 4 :
                     System.out.println("Enter Roll No For Delete The Record From the list");
                     rollNo = sc.nextInt();
                     s.Delete(rollNo);
                     break;
                case 5:
                     System.out.println("\n\nEnter Roll No to See A particular Record From DataBase :");
                     rollNo = sc.nextInt();
                     s.Search(rollNo);
                     break;
                case 6 :
                     s.Output();
                     break;
                case 7 :
                     return;
                default :
                      System.out.println("\nWrong Chioce");
     
            }//end of Switch
           }/*inner while closed*/
          }/*if closed*/
         }/*outer while closed*/ 
      }
}
          
  
          
          
      

No comments:

Post a Comment