public static void main(String[] args) {
ClassStudentName c = new ClassStudentName();
Scanner s= new Scanner(System.in);
char y='y';
char y1='y';
int choice;
while(true){
System.out.println("\t \t THIS IS A PROGRAM FOR CLASS STUDENT NAMES
MANAGEMENT\n ");
System.out.println("\t 1.To ADD a Student name press 1. \n\t 2.To UPDATE or
MODIFY a Student name press 2. \n\t 3.To REMOVE a Student name press 3. \n\t 4.To
SEE the Student names press 4.\n");
choice= s.nextInt();
s.nextLine();
switch(choice){
case 1:
while(true){
System.out.println("Enter the Student name in the format:
ROLL_NUMBER. NAME: ");
String Name= s.nextLine();
c.AddStudentName(Name);
System.out.println("Do you want to continue adding names?(Enter
n to exit or Enter any other key to continue):");
y1=s.next().charAt(0);
s.nextLine();
if(y1=='n')
break;
}
break;
case 2:
System.out.println("Enter the Roll Number of the Student whom do
you want to modify: ");
int roll = s.nextInt();
s.nextLine();
System.out.println("Enter the Name of the New Student:");
String Name= s.nextLine();
c.UpdateStudentName(roll, Name);
break;
case 3:
System.out.println("Enter the Roll Number of the Student to
Delete:");
int roll1= s.nextInt();
c.DeleteStudentName(roll1);
break;
case 4:
c.PrintStudentName();
break;
default:
System.out.println("Enter Properly!!");
}
System.out.println("DO YOU WANT TO CONTINUE WITH THIS PROGRAM? (Enter n to
exit or Enter any other key to continue):");
y= s.next().charAt(0);
s.nextLine();
if(y=='n')
break;
}
public class ClassStudentName {
private ArrayList<String> classname = new ArrayList<String>();
public void AddStudentName(String Name){
classname.add(Name);
}
public void PrintStudentName(){
int n= classname.size();
System.out.println("Your Class has "+ n + " number of students.\n"+
"Students name along with their Roll Numbers:");
for(int i=0;i<n;i++){
System.out.println((i+1) +" " +classname.get(i));
}
}
public void UpdateStudentName(int pos, String Name){
classname.set(pos-1, Name);
System.out.println("Name has been Modified or updated.\n");
}
public void DeleteStudentName(int pos){
classname.remove(pos-1);
System.out.println("Name has been Deleted Successfully.\n");
}