0% found this document useful (0 votes)
10 views4 pages

Java Student Management System Code

The document contains a Java program for a Student Management System that allows users to add, view, and update student records. It defines a Student class with attributes such as ID, name, age, course, and GPA, and includes methods for managing student data. The program features a menu-driven interface for user interaction and input validation for GPA and age.

Uploaded by

johnnamaecacho
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)
10 views4 pages

Java Student Management System Code

The document contains a Java program for a Student Management System that allows users to add, view, and update student records. It defines a Student class with attributes such as ID, name, age, course, and GPA, and includes methods for managing student data. The program features a menu-driven interface for user interaction and input validation for GPA and age.

Uploaded by

johnnamaecacho
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

import [Link].

ArrayList;
import [Link];
import [Link];

class Student {
private String studentID;
private String studentName;
private int studentAge;
private String studentCourse;
private double studentGPA;

public Student(String studentID, String studentName, int studentAge, String studentCourse,


double studentGPA) {
[Link] = studentID;
[Link] = studentName;
[Link] = studentAge;
[Link] = studentCourse;
[Link] = studentGPA;
}

public String getStudentID() {


return studentID;
}

public void setGpa(double studentGPA) {


if (studentGPA >= 0.0 && studentGPA <= 4.0) {
[Link] = studentGPA;
} else {
[Link]("Error: GPA must be between 0.0 and 4.0.");
}
}

public void displayInfo() {


[Link]("------------------------------");
[Link]("Student ID: " + studentID);
[Link]("Name: " + studentName);
[Link]("Age: " + studentAge);
[Link]("Course: " + studentCourse);
[Link]("GPA: " + studentGPA);
[Link]("------------------------------");
}
}

public class StudentManagementSystem {


private static ArrayList<Student> studentList = new ArrayList<>();
private static Scanner scanner = new Scanner([Link]);

public static void main(String[] args) {


while (true) {
displayMenu();
int choice = getMenuChoice();

switch (choice) {
case 1:
addStudent();
break;
case 2:
viewAllStudents();
break;
case 3:
updateGpa();
break;
case 4:
[Link](" Exiting the program. Goodbye!");
[Link]();
return;
default:
[Link](" Invalid choice. Please enter a number between 1 and 4.");
}
[Link]("\nPress Enter to continue...");
[Link]();
}
}

private static void displayMenu() {


[Link]("\n======= Student Management System =======");
[Link]("1. Add a New Student");
[Link]("2. View All Students");
[Link]("3. Update a Student's GPA");
[Link]("4. Exit");
[Link]("=======================================");
[Link]("Enter your choice: ");
}

private static int getMenuChoice() {


try {
int choice = [Link]();
[Link]();
return choice;
} catch (InputMismatchException e) {
[Link]();
return -1;
}
}

private static void addStudent() {


[Link]("\n--- Add a New Student ---");
[Link]("Enter Student ID: ");
String id = [Link]();

if (findStudentById(id) != null) {
[Link]("Error: A student with this ID already exists.");
return;
}

[Link]("Enter Student Name: ");


String name = [Link]();

[Link]("Enter Student Course: ");


String course = [Link]();

int age = getValidInt("Enter Student Age: ", 10, 100);


double gpa = getValidDouble("Enter Student GPA (0.0 - 4.0): ", 0.0, 4.0);

Student newStudent = new Student(id, name, age, course, gpa);


[Link](newStudent);
[Link]("Student added successfully!");
}

private static void viewAllStudents() {


[Link]("\n--- All Student Records ---");
if ([Link]()) {
[Link]("No students found. The list is empty.");
} else {
for (Student student : studentList) {
[Link]();
}
}
}

private static void updateGpa() {


[Link]("\n--- Update Student GPA ---");
[Link]("Enter the ID of the student to update: ");
String id = [Link]();

Student studentToUpdate = findStudentById(id);

if (studentToUpdate == null) {
[Link](" Student not found with that ID.");
} else {
[Link]("Found student:");
[Link]();

double newGpa = getValidDouble("Enter the new GPA (0.0 - 4.0): ", 0.0, 4.0);
[Link](newGpa);
[Link](" GPA updated successfully

You might also like