Saturday, 16 March 2013

/*A program designed by Raghav Raj in Java To create a Student Database */
import java.util.Scanner;
class Student
{
   String name[];
   int roll[];
   String add[];
   String course[];
   long fee_deposit[],dues[];
   long total = 100000;
   void Input()
   {
       Scanner sc = new Scanner(System.in);
       System.out.print("How many Records you want to store in Student Database :");
       int n = sc.nextInt();
       //array dynamic Memory Allocation
       name = new String[n];
       roll = new int[n];
       add  = new String[n];
       course = new String[n];
       fee_deposit = new long[n];
       System.out.println(">>>>>>>>>>>>>>Enter Details of "+n+" Student<<<<<<<<<<<<<< ");
       for(int i=0; i<n; i++)
       {
           System.out.println("Now Enter Detatils of Student "+(i+1)+" : ");
           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();
           System.out.print("\nEnter Course : ");
           course[i] = sc.next();
           System.out.print("\nEnter Fee for Deposit : ");
           fee_deposit[i] = sc.nextLong();
        }
   }
   void Output()
   {
       System.out.println("_________________________________________________");
       System.out.println("*********-->> Students Records <<--*********\n");
       System.out.println("_________________________________________________\n");
       System.out.println("_____________________________________________________________________________________");
       System.out.println("Roll\tName\t\tAddress\t\tCourse\tTotal\tFee Deposit\tDues");
       System.out.println("_____________________________________________________________________________________\n");
       for(int i=0; i<roll.length; i++)
       {
           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+"\t");
           System.out.print(fee_deposit[i]+"\t\t");
           System.out.print(dues[i]);
           System.out.println();
       }
   }
   void Dues()
   {
       dues = new long[roll.length];
       for(int i=0; i<roll.length; i++)
       {
           dues[i] = total-fee_deposit[i];
       }
   }

   void Search(int key)
   {
      
       int i;     
       for(i=0; i< roll.length; i++)
       {
           if(roll[i] == key)
           {
               System.out.println("Which Field you want to see of Roll No "+key+": " );
               System.out.print("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+"\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;
               }
               break;
           }
           else
               continue;
       }
      
       if( i == roll.length)
          System.out.println("Record Does Not Exists ");
    }
}
              
              
          
class StudentDatabase
{
      public static void main(String args[]) 
      {
          Student s = new Student();
          s.Input();
          s.Dues();
          s.Output();
          //to see a particular record in Database
          Scanner sc = new Scanner(System.in);
          System.out.println("Enter Roll No As Primary Key to See A particular Record From DataBase :");
          int rollNo = sc.nextInt();
          s.Search(rollNo);
         
         
      }
}
          
  
          
          
      

No comments:

Post a Comment