Programming Assignment: Unit 3
Hset Paing Htoo
Introduction to Computer Science Program, University of the People
CS 1102-01 Programming 1 AY2026-T5
Instructor : Sirajo Musa (Instructor)
July 6, 2026
Student Record Management System
1. Introduction
This assignment implements a console-based Student Record Management System in Java for a
university administrator. The program demonstrates encapsulation through private instance
variables, class-level (static) state and behavior through private static variables and static
methods, and defensive error handling for invalid or missing input. The system is organized into
three classes: Student, which models an individual student record; StudentManagement, which
maintains the shared list of all students and exposes static operations to add, update, and retrieve
them; and Main, which drives a menu-based administrator interface.
2. Concepts Applied
2.1 Encapsulation with Private Instance Variables
The Student class stores name, id, age, and grade as private instance variables. Each instance
variable belongs to a specific Student object, so every student created from the class has its own
independent copy of these fields (Eck, 2022, Section 4.2). Public getter and setter methods
control how these fields are read and modified from outside the class, which protects the internal
state of each Student object from uncontrolled changes.
2.2 Static Variables and Static Methods
The StudentManagement class uses private static variables — a List<Student> to hold every
student record and an int counter for the total number of students — because this information
describes the system as a whole rather than any single student. According to Eck (2022, Section
4.2), a static variable belongs to the class itself, so only one copy exists no matter how many
Student objects are created. All of StudentManagement's methods (addStudent, updateStudent,
viewStudent, viewAllStudents) are declared static so that the administrator interface can call
them directly on the class (e.g., [Link](...)) without needing to create a
StudentManagement object.
2.3 Menu-Driven Administrator Interface
The Main class presents a numbered menu in a while loop, reads the administrator's choice, and
uses a switch statement to dispatch to the correct operation. This mirrors the subroutine-based
program structure described by Eck (2022, Section 4.3), where the main method coordinates
smaller, single-purpose methods rather than containing all logic itself.
2.4 Error Handling
Two categories of invalid input are handled. First, non-numeric input for menu choices, student
IDs, or ages is caught with a try-catch block around [Link](), which throws a
NumberFormatException on bad input (Eck, 2022, Section 3.7, as applied earlier in this course).
Second, logical errors — such as looking up or updating a student ID that does not exist in the
system — are handled explicitly by checking the result of a private helper method,
findStudentById(), and printing a clear error message instead of allowing the program to crash or
fail silently.
3. Program Code
The system consists of three files: [Link], [Link], and [Link].
3.1 [Link]
public class Student {
private String name;
private int id;
private int age;
private String grade;
public Student(String name, int id, int age, String grade) {
[Link] = name;
[Link] = id;
[Link] = age;
[Link] = grade;
}
public String getName() { return name; }
public void setName(String name) { [Link] = name; }
public int getId() { return id; }
public int getAge() { return age; }
public void setAge(int age) { [Link] = age; }
public String getGrade() { return grade; }
public void setGrade(String grade) { [Link] = grade; }
@Override
public String toString() {
return "ID: " + id + " | Name: " + name
+ " | Age: " + age + " | Grade: " + grade;
}
}
3.2 [Link]
import [Link];
import [Link];
public class StudentManagement {
// Shared across the whole system - not tied to one Student
private static List<Student> students = new ArrayList<>();
private static int totalStudents = 0;
public static void addStudent(String name, int id, int age, String
grade) {
if (findStudentById(id) != null) {
[Link]("[Error] A student with ID " + id + "
already exists.");
return;
}
Student newStudent = new Student(name, id, age, grade);
[Link](newStudent);
totalStudents++;
[Link]("[Success] Student added. Total students: " +
totalStudents);
}
public static void updateStudent(int id, String name, int age, String
grade) {
Student student = findStudentById(id);
if (student == null) {
[Link]("[Error] Student ID " + id + " not
found.");
return;
}
if(![Link]()) {[Link](name);}
if(age > 0) {[Link](age);}
if(![Link]()) {[Link](grade);}
[Link]("[Success] Student ID " + id + "was updated
successfully!");}
public static void viewStudent(int id) {
Student student = findStudentById(id);
if (student == null) {
[Link]("[Error] Student ID " + id + " not
found.");
return;
}
[Link](student);
}
public static void viewAllStudents() {
if ([Link]()) {
[Link]("[Info] No students in the system yet.");
return;
}
for (Student s : students) {
[Link](s);
}
}
private static Student findStudentById(int id) {
for (Student s : students) {
if ([Link]() == id) {
return s;
}
}
return null;
}
public static int getTotalStudents() {
return totalStudents;
}
}
3.3 [Link]
import [Link];
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
boolean running = true;
[Link]("=== Student Record Management System ===");
while (running) {
printMenu();
int choice = -1;
try {
[Link]("Enter your choice: ");
choice = [Link]([Link]().trim());
} catch (NumberFormatException e) {
[Link]("[Error] Invalid input. Enter a number
1-5.");
continue;
}
switch (choice) {
case 1: addStudentFlow(scanner); break;
case 2: updateStudentFlow(scanner); break;
case 3: viewStudentFlow(scanner); break;
case 4: [Link](); break;
case 5:
[Link]("Goodbye!");
running = false;
break;
default:
[Link]("[Error] Choose a number between 1
and 5.");
}
}
[Link]();
}
private static void printMenu() {
[Link]("\n--- Administrator Menu ---");
[Link]("1. Add New Student");
[Link]("2. Update Student Information");
[Link]("3. View Student Details");
[Link]("4. View All Students");
[Link]("5. Exit");
}
private static void addStudentFlow(Scanner scanner) {
try {
[Link]("Enter student name: ");
String name = [Link]().trim();
if ([Link]()) {
[Link]("[Error] Name cannot be empty.");
return;
}
[Link]("Enter student ID: ");
int id = [Link]([Link]().trim());
[Link]("Enter student age: ");
int age = [Link]([Link]().trim());
[Link]("Enter student grade: ");
String grade = [Link]().trim();
[Link](name, id, age, grade);
} catch (NumberFormatException e) {
[Link]("[Error] ID and age must be numbers.");
}
}
private static void updateStudentFlow(Scanner scanner) {
try {
[Link]("Enter student ID to update: ");
int id = [Link]([Link]().trim());
[Link]("Enter new name: ");
String name = [Link]().trim();
[Link]("Enter new age: ");
int age = [Link]([Link]().trim());
[Link]("Enter new grade: ");
String grade = [Link]().trim();
[Link](id, name, age, grade);
} catch (NumberFormatException e) {
[Link]("[Error] ID and age must be numbers.");
}
}
private static void viewStudentFlow(Scanner scanner) {
try {
[Link]("Enter student ID to view: ");
int id = [Link]([Link]().trim());
[Link](id);
} catch (NumberFormatException e) {
[Link]("[Error] ID must be a number.");
}
}
}
4. Code Explanation
4.1 Student Class
Student represents a single student record. Its four fields are private, so no other class can read or
change them directly — access is only possible through the public getter and setter methods.
This is standard encapsulation: it keeps each Student object responsible for protecting its own
data, and it means validation logic could later be added inside a setter (for example, rejecting a
negative age) without changing any other class.
4.2 StudentManagement Class
StudentManagement holds the entire system's data in two private static variables: a
List<Student> and an int total counter. Because these are static, they exist once for the whole
class rather than once per object — there is never more than one master list of students,
regardless of how many times the class is referenced. All public methods are static as well, so the
Main class calls them directly (e.g., [Link]()) with no need to
instantiate a StudentManagement object. The private helper method findStudentById() is used
internally by addStudent, updateStudent, and viewStudent to search the list by ID; it returns null
when no match is found, which each caller checks before proceeding, giving a single consistent
place where the 'ID not found' error condition is detected.
4.3 Main Class and the Administrator Interface
[Link]() prints a welcome message and enters a while loop that keeps the menu running until
the administrator chooses to exit (option 5). Each iteration prints the menu, reads the choice, and
uses a switch statement to route to the matching private method: addStudentFlow(),
updateStudentFlow(), or viewStudentFlow(). Each flow method is responsible only for collecting
and validating console input before handing the actual data operation off to StudentManagement
— keeping the input-handling logic and the data-management logic cleanly separated.
4.4 Error Handling Strategy
Two kinds of errors are handled everywhere user input is involved. Invalid numeric input (letters
typed where a number is expected) triggers a NumberFormatException, which is caught so the
program prints a message and returns to the menu instead of crashing. Logical errors — such as
updating or viewing a student ID that was never added — are caught by checking whether
findStudentById() returned null, and printing '[Error] Student ID ... not found.' in that case.
Together these two checks mean the administrator interface never terminates unexpectedly due to
bad input.
5. Program Output
The following screenshots demonstrate the program running: adding a new student, viewing student details,
updating a student's information, attempting to view a non-existent student ID (error handling), and viewing all
students.
6. Instructions for Running the Program
● Save the three classes as [Link], [Link], and [Link] in the
same folder.
● Open a terminal in that folder.
● Compile all files: javac [Link] [Link] [Link]
● Run the program: java Main
● Follow the on-screen menu (1-5) to add, update, view a single student, view all students,
or exit.
● When adding or updating a student, enter the ID and age as whole numbers; the program
will reject non-numeric input and re-show the menu.
7. Discussion
7.1 Design Decisions
Keeping the student list and total counter as private static fields inside StudentManagement,
rather than as public fields or as fields on Main, follows the requirement that class-wide data be
encapsulated and only reachable through the class's own static methods. Separating the three
classes by responsibility — data (Student), storage and business logic (StudentManagement), and
user interaction (Main) — also makes the system easier to extend later, for example by swapping
the console interface for a graphical one without touching StudentManagement at all.
7.2 Limitations and Possible Improvements
● No persistence: all student records are lost when the program exits; a file- or
database-backed store would fix this.
● No input validation beyond type checking: for example, a negative age or an empty grade
string is currently accepted.
● Linear search: findStudentById() scans the whole list, which is fine for small class sizes
but would not scale to a very large student body without an index such as a HashMap
keyed by ID.
● No delete option: the current menu cannot remove a student record, which a full system
would likely need.
8. Conclusion
This assignment applied static variables and static methods to build a shared, class-wide store of
student records, alongside private instance variables to protect the data of each individual
Student. The resulting Student Record Management System offers a menu-driven administrator
interface backed by defensive error handling, satisfying the assignment's requirements for
student updates, student management, an administrator interface, and robust handling of invalid
or missing input.
References
Eck, D. J. (2022). Introduction to programming using Java, version 9, JavaFX edition.
[Link]
Neso Academy. (2020, June 23). Static variables and static methods in Java [Video]. YouTube.
[Link]