0% found this document useful (0 votes)
40 views

Public Static Void New New Char Char Int While True /T /T /N /T /N/T /N/T /N/T /N

This program allows a user to manage student names by adding, updating, removing, and viewing student names stored in an ArrayList. The user is prompted with a menu to choose an operation and input any necessary information like a student name or roll number. Based on the choice, the appropriate method from the ClassStudentName class is called to perform the operation on the ArrayList, such as adding a new name, updating an existing name, deleting a name, or printing all names. The user can continue performing operations in a loop until choosing to exit.

Uploaded by

poujhit
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Public Static Void New New Char Char Int While True /T /T /N /T /N/T /N/T /N/T /N

This program allows a user to manage student names by adding, updating, removing, and viewing student names stored in an ArrayList. The user is prompted with a menu to choose an operation and input any necessary information like a student name or roll number. Based on the choice, the appropriate method from the ClassStudentName class is called to perform the operation on the ArrayList, such as adding a new name, updating an existing name, deleting a name, or printing all names. The user can continue performing operations in a loop until choosing to exit.

Uploaded by

poujhit
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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");
}

You might also like