You are on page 1of 3

Q) Make a Student Management Program using array

package javaProject;

import java.util.Scanner;

class Student50{
int rollno;
String name;
String college;

public Student50(int rollno,String name,String college){


super();
this.rollno=rollno;
this.name=name;
this.college=college;
}
public String toString() {
return rollno+" "+name+" "+college;
}
}

class StudDemo{
public static void main(String[] args) {
int count=0;
int choice=0;
int rollno;
String name;
String college;
Scanner sc=new Scanner(System.in);

int roll[]=new int[10];


String nm[]=new String[10];
String clg[]=new String[10];

do {
System.out.println("\nStudent Management System\
n**************************************\n");
System.out.println("Enter: 1. For insert \n\t2. For update \
n\t3. For delete \n\t4. Select all \n\t0. For exit");
choice=sc.nextInt();
switch(choice) {
case 1:

System.out.print("Enter student roll number: ");


rollno=sc.nextInt();

System.out.print("Enter student name: ");


name=sc.next();
System.out.print("Enter college name: ");
college=sc.next();

roll[count]=rollno;
nm[count]=name;
clg[count]=college;
System.out.println("\nStudent record added successfully
!!!\n");

count++;
break;
case 2:
System.out.println("Enter roll no for updating student
data:");
rollno=sc.nextInt();
boolean isPresent = false;
for(int i=0;i<count;i++) {
if(roll[i]!=0 && roll[i]==rollno) {

System.out.print("Enter Student name: ");


nm[i]=sc.next();

System.out.println("Enter college name:


");
clg[i]=sc.next();

System.out.println("\nStudent record
updated successfully !!!\n");
isPresent = true;
}

}
if(!isPresent) {
System.out.println("Roll number "+rollno+" is not
exist !!!");
}

break;
case 3:
System.out.println("Enter roll no for deleting
data :");
rollno=sc.nextInt();
boolean isPresent1 = false;

for(int i=0;i<count;i++) {
if(roll[i]!=0 && roll[i]==rollno) {
roll[i]=0;
nm[i]=null;
clg[i]=null;
System.out.print("\nStudent record deleted
successfully !!!\n");
isPresent1 = true;
}

}
if(!isPresent1) {
System.out.println("Roll number "+rollno+" is not
exist !!!");
}
break;
case 4:

for(int i=0;i<count;i++) {
if(roll[i]!=0) {
System.out.println(roll[i]+" "+nm[i]+"
"+clg[i]);

}
}

break;

case 0:
break;

default:
System.out.println("Enter valid choice.....");
break;

}while(choice!=0);
sc.close();
}
}

You might also like