Saturday, November 9, 2019

storing student data using java

package pack1;

import java.util.Scanner;

class hh{
String Name;
int roll;
String branch;
String[] core = new String[10];  
String[] elective = new String[10];
int cor,ele;
public static void main(String args[])
{
    int n2=0;
    hh[] obj = new hh[20];
    while(1!=0) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter 1 -> to add data");
        System.out.println("Enter 2 - > to change his / her elective courses");
        System.out.println("Enter 3 -> to change his/her core subjects");
        System.out.println("Enter 4 -> to print particular");
        System.out.println("Enter 5 -> for particular branch");
        System.out.println("Enter 6-> to exit");
        int n1 = scan.nextInt();
        switch (n1)
        {
            case 1 :for (int i = 0+n2; i < n2+n1; i++) {
                String[] core = new String[5];
                String[] elective = new String[5];

                Scanner s2 = new Scanner(System.in);
                System.out.println("Enter name ,branch, roll no,cor and elective subjects");
                String Name = s2.nextLine();
                String branch = s2.nextLine();
                int roll = s2.nextInt();
                System.out.println("Enter how many core subjects ");
                int cor = s2.nextInt();
                System.out.println("ENter how many elective subjects have");
                int ele = s2.nextInt();
                if(cor+ele>6)
                {
                    System.out.println("!!!Something went wrong!!!\n\t enter again");
                    break;
                }
                System.out.println("ENter his "+cor+" Subjects");
                              for(int j=0;j<cor;j++)
                {
                    Scanner scan1 = new Scanner(System.in);
                    System.out.println("Enter " +(j+1)+" Core subject");
                    core[j] = scan1.nextLine();
                }
                for(int j=0;j<ele;j++)
                {
                    Scanner scan1 = new Scanner(System.in);
                    System.out.println("Enter " +(j+1)+" elective subject");
                    elective[j] = scan1.nextLine();
                }

                obj[i] = new hh(Name, roll,branch,core,elective,cor,ele);

                n2++;
                break;
            }
            break;
            case 2:
                electiv(obj,n2);
                break;
            case 3:co(obj,n2);
            break;
            case 4:method(obj,n2);
                   break;
            case 5: branch(obj,n2);
            break;
            case 6 :
                System.exit(0);
            default: System.out.println("Enter correct one");
        }

    }

}
 // change core subjects     static void co(hh[] obj, int n2) {
Scanner scan = new Scanner(System.in);
    System.out.println("Enter student name");
String name = scan.nextLine();
    for(int i=0;i<n2;i++)
    {
        if(name.equals(obj[i].Name))
        {
            Scanner s2 = new Scanner(System.in);
            System.out.println("Enter how many core subjects ");
            int cor = s2.nextInt();
            if(cor+obj[i].ele>6)
            {
                System.out.println("!!!Something went wrong!!!\n\t enter again");
                break;
            }
            System.out.println("ENter his "+cor+" Subjects");
            for(int j=0;j<cor;j++)
            {
                Scanner scan1 = new Scanner(System.in);
                System.out.println("Enter " +(j+1)+" Core subject");
                obj[i].core[j] = scan1.nextLine();
            }
        }
}

}
// To change elective courses    static void electiv(hh[] obj, int n2) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter student name");
        String name = scan.nextLine();
        for(int i=0;i<n2;i++)
        {
            if(name.equals(obj[i].Name))
            {
                Scanner s2 = new Scanner(System.in);
                System.out.println("Enter how many elective subjects ");
                int ele = s2.nextInt();
                if(ele+obj[i].cor>6)
                {
                    System.out.println("!!!Something went wrong!!!\n\t enter again");
                    break;
                }
                System.out.println("ENter his "+ele+" Subjects");
                for(int j=0;j<ele;j++)
                {
                    Scanner scan1 = new Scanner(System.in);
                    System.out.println("Enter " +(j+1)+" elective subject");
                    obj[i].elective[j] = scan1.nextLine();
                }
            }
        }

    }
//branch wise    static void branch(hh[] obj, int n2) {
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter a branch name ");
    String br = scan.nextLine();
         for(int i=0;i<n2;i++) {
             if(br.equals(obj[i].branch)) {
                 System.out.println("Name:" + obj[i].Name + "\nRoll:" + obj[i].roll+"\nBranch:"+obj[i].branch);
                 System.out.println("core subjects:");
                 for(int j=0;j<obj[i].cor;j++)
                 {
                     System.out.println("\t "+obj[i].core[j]);
                 }
                 System.out.println("elective subjects:");
                 for(int j=0;j<obj[i].ele;j++)
                 {
                     System.out.println("\t "+obj[i].elective[j]);
                 }
             }
             else             {
                 continue;
             }
         }
    }
//costructor    hh(String Name, int roll, String branch,String[] core,String[] elective,int cor,int ele)
{
    this.Name=Name;
    this.roll=roll;
    this.branch=branch;
    this.cor=cor;
    this.ele=ele;
    for (int i=0;i<cor;i++)
    {
        this.core[i]=core[i];
    }
    for (int i=0;i<cor;i++)
    {
        this.elective[i]=elective[i];
    }
}

//Pring name wisestatic void method(hh[] obj,int n2)
{
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter name to search");
    String name = sc.nextLine();
    for(int i=0;i<n2;i++) {
          if(name.equals(obj[i].Name)) {
              System.out.println("Name:" + obj[i].Name + "\nRoll:" + obj[i].roll+"\nBranch:"+obj[i].branch);
              System.out.println("core subjects:");
              for(int j=0;j<obj[i].cor;j++)
              {
                  System.out.println("\t "+obj[i].core[j]);
              }
              System.out.println("elective subjects:");
              for(int j=0;j<obj[i].ele;j++)
              {
                  System.out.println("\t "+obj[i].elective[j]);
              }
          }
          else          {
              continue;

No comments:

Post a Comment

Manhattan Distance Heuristic

#include<stdio.h> #include<stdlib.h> struct node{  int arr[10][10];  int i,j;  int md; }; int a[10][10]; struct node*...