0% found this document useful (0 votes)
2 views3 pages

P1

The document contains a Java implementation of a Student Management System that allows users to add, display, search, update, and delete student records. It defines a Student class with attributes like roll number, name, age, grade, and marks, and provides methods for managing a list of students. The main program runs a menu-driven interface for user interaction to perform various operations on the student data.

Uploaded by

aryanrajpro949
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

P1

The document contains a Java implementation of a Student Management System that allows users to add, display, search, update, and delete student records. It defines a Student class with attributes like roll number, name, age, grade, and marks, and provides methods for managing a list of students. The main program runs a menu-driven interface for user interaction to perform various operations on the student data.

Uploaded by

aryanrajpro949
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

ArrayList;
import java.util.Scanner;

class Student {
int rollNumber;
String name;
int age;
String grade;
double marks;

public Student(int rollNumber, String name, int age, String grade, double
marks) {
this.rollNumber = rollNumber;
this.name = name;
this.age = age;
this.grade = grade;
this.marks = marks;
}

public void display() {


System.out.println("Roll Number: " + rollNumber);
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Grade: " + grade);
System.out.println("Marks: " + marks);
System.out.println("-----------------------------");
}
}

public class StudentManagementSystem {


static ArrayList<Student> studentList = new ArrayList<>();
static Scanner sc = new Scanner(System.in);

public static void main(String[] args) {


int choice;
do {
System.out.println("\n***** STUDENT MANAGEMENT SYSTEM *****");
System.out.println("1. Add Student");
System.out.println("2. Display All Students");
System.out.println("3. Search Student by Roll Number");
System.out.println("4. Update Student");
System.out.println("5. Delete Student");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
sc.nextLine(); // consume newline

switch (choice) {
case 1:
addStudent();
break;
case 2:
displayAllStudents();
break;
case 3:
searchStudent();
break;
case 4:
updateStudent();
break;
case 5:
deleteStudent();
break;
case 6:
System.out.println("Exiting... Thank you!");
break;
default:
System.out.println("Invalid choice! Try again.");
}

} while (choice != 6);


}

static void addStudent() {


System.out.print("Enter Roll Number: ");
int roll = sc.nextInt();
sc.nextLine();
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Age: ");
int age = sc.nextInt();
sc.nextLine();
System.out.print("Enter Grade: ");
String grade = sc.nextLine();
System.out.print("Enter Marks: ");
double marks = sc.nextDouble();
sc.nextLine();

Student s = new Student(roll, name, age, grade, marks);


studentList.add(s);
System.out.println("Student added successfully!");
}

static void displayAllStudents() {


if (studentList.isEmpty()) {
System.out.println("No students found.");
return;
}

for (Student s : studentList) {


s.display();
}
}

static void searchStudent() {


System.out.print("Enter Roll Number to search: ");
int roll = sc.nextInt();
boolean found = false;

for (Student s : studentList) {


if (s.rollNumber == roll) {
s.display();
found = true;
break;
}
}

if (!found) {
System.out.println("Student not found.");
}
}

static void updateStudent() {


System.out.print("Enter Roll Number to update: ");
int roll = sc.nextInt();
sc.nextLine();
boolean found = false;

for (Student s : studentList) {


if (s.rollNumber == roll) {
System.out.println("Current details:");
s.display();

System.out.print("Enter New Name: ");


s.name = sc.nextLine();
System.out.print("Enter New Age: ");
s.age = sc.nextInt();
sc.nextLine();
System.out.print("Enter New Grade: ");
s.grade = sc.nextLine();
System.out.print("Enter New Marks: ");
s.marks = sc.nextDouble();
sc.nextLine();

System.out.println("Student updated successfully!");


found = true;
break;
}
}

if (!found) {
System.out.println("Student not found.");
}
}

static void deleteStudent() {


System.out.print("Enter Roll Number to delete: ");
int roll = sc.nextInt();
boolean found = false;

for (int i = 0; i < studentList.size(); i++) {


if (studentList.get(i).rollNumber == roll) {
studentList.remove(i);
System.out.println("Student deleted successfully!");
found = true;
break;
}
}

if (!found) {
System.out.println("Student not found.");
}
}
}

You might also like