0% found this document useful (0 votes)
37 views11 pages

Document

The document provides a Java implementation of a Student Record Management System, including code, explanations, and instructions for running the program. It features functionalities to add, update, and view student details, along with error handling for duplicate IDs and invalid inputs. The document also includes references for Java documentation and best practices for coding.

Uploaded by

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

Document

The document provides a Java implementation of a Student Record Management System, including code, explanations, and instructions for running the program. It features functionalities to add, update, and view student details, along with error handling for duplicate IDs and invalid inputs. The document also includes references for Java documentation and best practices for coding.

Uploaded by

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

Below is a Java implementation of a Student Record Management System that meets the

requirements outlined. The program is designed to be robust, user-friendly, and well-


documented. I'll provide the code, explanation, and instructions for running the program.

Java Code: Student Record Management System

```java
import java.util.ArrayList;
import java.util.Scanner;

public class StudentRecordManagementSystem {

// Static variables to store student data


private static ArrayList<Student> studentList = new ArrayList<>();
private static int totalStudents = 0;

// Student class to represent student data


static class Student {
String name;
int id;
int age;
String grade;

// Constructor to initialize student details


public Student(String name, int id, int age, String grade) {
this.name = name;
this.id = id;
this.age = age;
this.grade = grade;
}
// Override toString() to display student details
@Override
public String toString() {
return "ID: " + id + ", Name: " + name + ", Age: " + age + ", Grade: " + grade;
}
}

// Method to add a new student


public static void addStudent(Scanner scanner) {
System.out.println("\n--- Add New Student ---");
System.out.print("Enter Student Name: ");
String name = scanner.nextLine();
System.out.print("Enter Student ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Student Age: ");
int age = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Student Grade: ");
String grade = scanner.nextLine();

// Check if student ID already exists


for (Student student : studentList) {
if (student.id == id) {
System.out.println("Error: Student ID already exists!");
return;
}
}
// Add new student to the list
studentList.add(new Student(name, id, age, grade));
totalStudents++;
System.out.println("Student added successfully!");
}

// Method to update student information


public static void updateStudent(Scanner scanner) {
System.out.println("\n--- Update Student Information ---");
System.out.print("Enter Student ID to update: ");
int id = scanner.nextInt();
scanner.nextLine(); // Consume newline

// Find the student by ID


Student studentToUpdate = null;
for (Student student : studentList) {
if (student.id == id) {
studentToUpdate = student;
break;
}
}

if (studentToUpdate == null) {
System.out.println("Error: Student ID not found!");
return;
}

// Prompt for updated details


System.out.print("Enter new Name (leave blank to keep current): ");
String name = scanner.nextLine();
if (!name.isEmpty()) {
studentToUpdate.name = name;
}

System.out.print("Enter new Age (leave 0 to keep current): ");


int age = scanner.nextInt();
scanner.nextLine(); // Consume newline
if (age != 0) {
studentToUpdate.age = age;
}

System.out.print("Enter new Grade (leave blank to keep current): ");


String grade = scanner.nextLine();
if (!grade.isEmpty()) {
studentToUpdate.grade = grade;
}

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


}

// Method to view student details


public static void viewStudentDetails(Scanner scanner) {
System.out.println("\n--- View Student Details ---");
System.out.print("Enter Student ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // Consume newline
// Find the student by ID
Student studentToView = null;
for (Student student : studentList) {
if (student.id == id) {
studentToView = student;
break;
}
}

if (studentToView == null) {
System.out.println("Error: Student ID not found!");
} else {
System.out.println(studentToView);
}
}

// Method to display the main menu


public static void displayMenu() {
System.out.println("\n--- Student Record Management System ---");
System.out.println("1. Add New Student");
System.out.println("2. Update Student Information");
System.out.println("3. View Student Details");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
}

// Main method to run the program


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean running = true;

while (running) {
displayMenu();
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline

switch (choice) {
case 1:
addStudent(scanner);
break;
case 2:
updateStudent(scanner);
break;
case 3:
viewStudentDetails(scanner);
break;
case 4:
running = false;
System.out.println("Exiting the program. Goodbye!");
break;
default:
System.out.println("Invalid choice! Please try again.");
}
}

scanner.close();
}
}
Explanation of the Code
1. Student Class:
- Represents a student with attributes: `name`, `id`, `age`, and `grade`.
- Includes a constructor to initialize these attributes and an overridden `toString()` method
to display student details.

2. Static Variables:
- `studentList`: An `ArrayList` to store all student objects.
- `totalStudents`: Tracks the total number of students added.

3. Methods:
- `addStudent()`: Adds a new student to the list after validating the ID.
- `updateStudent()`: Updates student details based on the provided ID.
- `viewStudentDetails()`: Displays details of a specific student by ID.
- `displayMenu()`: Displays the main menu for the administrator.

4. Error Handling:
- Checks for duplicate student IDs when adding a new student.
- Handles cases where a student ID is not found during updates or viewing.

5. Main Method:
- Runs the program in a loop, allowing the administrator to perform multiple operations
until they choose to exit.

Instructions for Running the Program

1. Prerequisites:
- Install Java Development Kit (JDK) on your system.
- Ensure the `javac` and `java` commands are available in your terminal or command
prompt.
2. Steps:
- Copy the code into a file named `StudentRecordManagementSystem.java`.
- Open a terminal or command prompt and navigate to the directory containing the file.
- Compile the program using the command:
```
javac StudentRecordManagementSystem.java
```
- Run the program using the command:
```
java StudentRecordManagementSystem
```
- Follow the on-screen menu to add, update, or view student details.

Documentation

1. How to Use the Program


- When the program starts, the administrator is presented with a menu:
- Option 1:Add a new student by providing their name, ID, age, and grade.
- Option 2: Update an existing student's information by entering their ID and providing new
details.
- Option 3: View a student's details by entering their ID.
- Option 4: Exit the program.

2. Error Handling
- The program ensures that:
- Duplicate student IDs are not allowed.
- Invalid inputs (e.g., non-existent IDs) are handled gracefully.
3. Best Practices
- The code follows Java coding conventions, including meaningful variable names, proper
indentation, and modular design.
- Static variables are used to maintain the list of students and the total count.

1. Java Documentation
- Official Java Documentation: The primary reference for understanding Java syntax, data
structures (like `ArrayList`), and best practices.
- Link: [https://docs.oracle.com/javase/8/docs/](https://docs.oracle.com/javase/8/docs/

2. Java Programming Resources


- Java ArrayList: Used to dynamically store and manage student records.
- Reference:
[https://www.w3schools.com/java/java_arraylist.asp](https://www.w3schools.com/java/
java_arraylist.asp)
- Java Scanner Class:Used for taking user input from the console.
- Reference: [https://www.javatpoint.com/Scanner-class](https://www.javatpoint.com/
Scanner-class)
- Java Static Variables: Used to maintain the list of students and the total count across the
program.
3. Error Handling
- Input Validation: Ensures that invalid inputs (e.g., duplicate IDs, non-existent IDs) are
handled gracefully.
- Reference:
[https://www.baeldung.com/java-exception-handling](https://www.baeldung.com/java-
exception-handling)
4. Coding Best Practices
- Meaningful Variable Names: Follows Java naming conventions for variables, methods, and
classes.
- Reference: [https://www.oracle.com/java/technologies/javase/codeconventions-
namingconventions.html](https://www.oracle.com/java/technologies/javase/codeconventions-
namingconventions.html)
- Modular Design: The program is divided into logically separated methods for better
readability and maintainability.
- Reference:
[https://www.geeksforgeeks.org/java-programming-basics/](https://www.geeksforgeeks.org/
java-programming-basics/)
5. Menu-Driven Interface
- Switch-Case Statements: Used to handle user choices in the menu.
- Reference: [https://www.javatpoint.com/java-switch](https://www.javatpoint.com/java-
switch)
6. Comprehensive Documentation
-Java Comments: Used to document the code for better understanding.
- Reference: [https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html]
(https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html)
7. Additional Resources
- Java Tutorials: General Java programming tutorials for beginners.
- Link: [https://www.tutorialspoint.com/java/index.htm](https://www.tutorialspoint.com/
java/index.htm)
- Java File Handling: For future enhancements, such as saving student records to a file.
- Reference: [https://www.javatpoint.com/java-file-class](https://www.javatpoint.com/java-
file-class)

You might also like