Java Console Program Design
Below a complete Java program designed for a console-based student record management
system that meets the assignment requirements:
Student data organized in separate variables, including their name, ID, age, and grade.
No student class; instead, all the logic and data are kept within a classless structure
known as StudentManagement.
Used static arrays to hold student information, along with a static variable totalStudents
to keep track of the total number of students.
The admin interface is menu-based and includes input validation along with some basic
error handling.
Key Design Choices
This program is built around the basic principles of Create, Update, Read, and Delete (CRUD)
operations, which are essential for simplifying administrative tasks and minimizing manual
errors (Patil et al., 2023). The code reflects these concepts in a straightforward, single-class
format that’s perfect for learning purposes. It focuses on clear input handling and includes error
checking (Barot & Jain, 2025).
Student Record Management System Java Program
import [Link];
import [Link];
public class StudentManagement {
// Max number of students the system can hold
static final int MAX_STUDENTS = 100;
// Separate arrays for each field (no Student class)
static String[] studentNames = new String[MAX_STUDENTS];
static String[] studentIds = new String[MAX_STUDENTS];
static int[] studentAges = new int[MAX_STUDENTS];
static double[] studentGrades = new double[MAX_STUDENTS];
// Total number of students currently stored
static int totalStudents = 0;
static Scanner scanner = new Scanner([Link]);
public static void main(String[] args) {
runMenu();
}
// Main administrator loop
public static void runMenu() {
while (true) {
[Link]("\n=== Student Record Management System ===");
[Link]("1. Add New Student");
[Link]("2. Update Student Information");
[Link]("3. View Student Details");
[Link]("4. View All Students");
[Link]("5. Exit");
[Link]("Enter your choice (1-5): ");
int choice = readIntSafely();
switch (choice) {
case 1:
addStudent();
break;
case 2:
updateStudent();
break;
case 3:
viewStudent();
break;
case 4:
viewAllStudents();
break;
case 5:
[Link]("Exiting system. Goodbye!");
return;
default:
[Link]("Invalid choice. Please select 1–5.");
}
}
}
// Add a new student if capacity not exceeded and ID is unique
public static void addStudent() {
if (totalStudents >= MAX_STUDENTS) {
[Link]("Cannot add more students. Maximum capacity reached.");
return;
}
[Link]("\n--- Add New Student ---");
[Link]("Enter Student ID: ");
String id = [Link]().trim();
if (findStudentIndexById(id) != -1) {
[Link]("Error: A student with this ID already exists.");
return;
}
[Link]("Enter Student Name: ");
String name = [Link]().trim();
[Link]("Enter Age: ");
int age = readPositiveInt();
[Link]("Enter Grade (0.0 - 100.0): ");
double grade = readGrade();
// Store in parallel arrays at index totalStudents
studentIds[totalStudents] = id;
studentNames[totalStudents] = name;
studentAges[totalStudents] = age;
studentGrades[totalStudents] = grade;
totalStudents++;
[Link]("Student added successfully.");
}
// Update existing student by ID
public static void updateStudent() {
[Link]("\n--- Update Student Information ---");
[Link]("Enter Student ID to update: ");
String id = [Link]().trim();
int index = findStudentIndexById(id);
if (index == -1) {
[Link]("Error: Student ID not found.");
return;
}
[Link]("Current details:");
printStudentAtIndex(index);
[Link]("Enter new name (leave blank to keep current): ");
String newName = [Link]().trim();
if (![Link]()) {
studentNames[index] = newName;
}
[Link]("Enter new age (or -1 to keep current): ");
int newAge = readIntSafely();
if (newAge > 0) {
studentAges[index] = newAge;
}
[Link]("Enter new grade (-1 to keep current): ");
double newGrade = readDoubleSafely();
if (newGrade >= 0.0 && newGrade <= 100.0) {
studentGrades[index] = newGrade;
} else if (newGrade != -1.0) {
[Link]("Invalid grade entered. Keeping existing grade.");
}
[Link]("Student information updated.");
}
// View single student by ID
public static void viewStudent() {
[Link]("\n--- View Student Details ---");
[Link]("Enter Student ID to view: ");
String id = [Link]().trim();
int index = findStudentIndexById(id);
if (index == -1) {
[Link]("Error: Student ID not found.");
return;
}
printStudentAtIndex(index);
}
// View all students
public static void viewAllStudents() {
[Link]("\n--- All Students ---");
if (totalStudents == 0) {
[Link]("No students found.");
return;
}
for (int i = 0; i < totalStudents; i++) {
printStudentAtIndex(i);
[Link]("---------------------------");
}
}
// Helper: print student record at a given index
private static void printStudentAtIndex(int index) {
[Link]("ID: " + studentIds[index]);
[Link]("Name: " + studentNames[index]);
[Link]("Age: " + studentAges[index]);
[Link]("Grade: " + studentGrades[index]);
}
// Helper: find student index by ID, or -1 if not found
public static int findStudentIndexById(String id) {
for (int i = 0; i < totalStudents; i++) {
if (studentIds[i].equalsIgnoreCase(id)) {
return i;
}
}
return -1;
}
// Safe integer input with error handling
private static int readIntSafely() {
while (true) {
try {
int value = [Link]([Link]().trim());
return value;
} catch (NumberFormatException e) {
[Link]("Invalid number. Please enter an integer: ");
}
}
}
// Read positive integer (e.g., for age)
private static int readPositiveInt() {
while (true) {
int value = readIntSafely();
if (value > 0) {
return value;
}
[Link]("Value must be positive. Try again: ");
}
}
// Safe double input
private static double readDoubleSafely() {
while (true) {
try {
return [Link]([Link]().trim());
} catch (NumberFormatException e) {
[Link]("Invalid number. Please enter a decimal value: ");
}
}
}
// Read grade between 0 and 100
private static double readGrade() {
while (true) {
double grade = readDoubleSafely();
if (grade >= 0.0 && grade <= 100.0) {
return grade;
}
[Link]("Grade must be between 0.0 and 100.0. Try again: ");
}
}
}
Documentation
1. Overview
This Student Record Management System is a console-based Java application that allows an
administrator to:
Add new students
Update existing student information
View a single student’s details by ID
View all students currently in the system
All student data is stored using individual arrays (name, ID, age, grade) and static variables, as
required. No separate Student class is used.
2. Program Structure
Static Data Fields
MAX_STUDENTS: This sets a strict limit on the sizes of our arrays.
studentNames, studentIds, studentAges, studentGrades: We have parallel arrays here;
that means the index "i" in all these arrays will refer to the same student.
totalStudents: This keeps track of how many student records are currently active and
also indicates the next available index.
scanner: We have a shared Scanner for getting input from the console.
These variables are static, so every method interacts with the same shared state, which gives the
feel of a “classless” management module (Zhou, 2018).
main(String[] args)
This is the entry point of our application.
It calls the `runMenu()` function once, and then remains in the menu loop until the user
decides to exit.
The function does not retain any local state beyond the parameters, which are essentially
ignored.
runMenu()
Control flow:
The application runs indefinitely in a `while (true)` loop, ensuring the admin interface
stays up and running.
Each iteration displays the menu options to the user.
It reads the user’s choice using `readIntSafely()`, which helps prevent any invalid
numeric input.
Based on the user’s choice, it uses a switch choice
o If the choice is 1: it calls `addStudent()`.
o If the choice is 2: it calls `updateStudent()`.
o If the choice is 3: it calls `viewStudent()`.
o If the choice is 4: it calls `viewAllStudents()`.
o If the choice is 5: it prints a message and exits the main function.
o For any other input, an error message is displayed, and the loop continues.
All of these methods are static and are part of a single class called StudentRecordSystem,
reflecting the concept of a “classless structure” for managing student entities.
Variables:
Local int choice holds user’s menu selection.
addStudent()
Control flow:
First, check if the (totalStudents >= MAX_STUDENTS)allowed. If it is, display a
capacity error message and return
Next, ask for the student's id and make sure to read the entire line, trim() to remove any
unnecessary whitespace.
Then, call the function findStudentIndexById(id)to find the student's index by their id.
If it returns a result ≠ −1, that means there’s an ID collision. In that case, print an error
message and stop the process.
After that, prompt for the student's name and read their response.
Now, ask for the student’s age. Use the function readPositiveInt() that checks for
positive integers to ensure it’s greater than 0.
Then, prompt for the student’s grade and utilize the function readGrade() designed to
validate the grade to confirm it falls between 0.0 and 100.0.
Once you have all the information, store the values in their respective arrays at the
current index of totalStudents.
increment the totalStudents count.
Finally, print a success message to confirm everything went smoothly.
Variables:
Local String id, name; int age; double grade.
updateStudent()
Control flow:
Start by asking for the student ID, then read and trim the input.
Use the function int index = findStudentIndexById(id)` to locate the index. If it returns
-1, display "not found" and return
Show the current information by calling `printStudentAtIndex(index)`.
Ask for the new name: If the line is not empty, overwrite `studentNames[index]` with the
new name.
Inquire about the new age: Use newAge = readIntSafely() to get the input. If newAge >
0, overwrite; if <=0, keep the old age unchanged.
Request the new grade: Use newGrade = readDoubleSafely()to read the input.
If 0.0 <= newGrade <= 100.0, overwrite the grade Else if newGrade == -1.0, keep the
current grade. For any other input, show an invalid warning and maintain the existing
grade.
Finally, print a confirmation message.
Variables:
String id, newName; int index, newAge; double newGrade.
Error handling:
If there's no ID, we’ll return early.
For age or grade text that’s invalid, safe readers will catch it.
If a grade is out of the acceptable range, warning and ignore.
viewStudent()
Control flow:
Prompt the user for their ID.
Use the function [Link] find the student index by ID.
If the index is -1, display an error message and return.
Otherwise, call the function printStudentAtIndex(index)to print the student details at
the specified index.
Variables:
Local String id; int index.
viewAllStudents()
Control flow:
If totalStudents == 0, print “No students” and return.
For each student, loop through the range(int i = 0; i < totalStudents; I and for each
index, call the function printStudentAtIndex(i)to print the student's details.
After that, print a line to separate the entries.
Variables:
Local loop index int i.
printStudentAtIndex(int index)
Utility that prints a single record using the same index on all arrays.
No branching; straightforward field access and [Link].
findStudentIndexById(String id)
Control flow:
Linear search for a case-insensitive match: For i from 0 to totalStudents - 1: If
studentIds[i].equalsIgnoreCase(id), return i. If no match, return −1.
Variables:
Parameter id (target ID).
Loop index i.
readIntSafely()
Goal:
Robustly read an integer from the console.
Control flow:
Infinite while (true): Read a line with [Link]().trim().
Try [Link](...). On success, return value. On NumberFormatException,
prompt again.
No state outside local value.
readPositiveInt()
Control flow:
Calls readIntSafely() repeatedly until value > 0. If value ≤ 0, prints error and loops.
Used for age to enforce non-negative logic.
readDoubleSafely()
Goal: Same as readIntSafely() but for double.
Control flow:
Infinite loop: Read and trim line. Try [Link](...). On success, return. On
error, print message and ask again.
readGrade()
Control flow:
Calls readDoubleSafely() in a loop.
If result is between 0.0 and 100.0 (inclusive), return it.
Else, print constraint message and retry.
3. Error Handling
The program has implemented some solid error handling strategies:
Invalid Menu Option: If a user enters anything outside the range of 1 to 5, the program
responds with an error message and redisplays the menu for clarity.
Non-Numeric Inputs: For all fields that require numbers (like ID, age, and grade), we use a try-
catch block to catch any `NumberFormatException`. If there's an issue with parsing, an error
message is shown. Specifically:
In the `addStudent()` function, the student won't be added if there's an error.
In `updateStudent()`, the field that had the invalid input won’t be updated.
Student ID Not Found: The `findStudentIndexById` function returns -1 if the provided ID
doesn't exist. Both `updateStudent()` and `viewStudent()` check for this -1 return value and
display "Error: Student ID not found." to the user.
Capacity Reached: Before adding a new student, the `addStudent()` function checks if the total
number of students is already at the maximum limit defined by `MAX_STUDENTS`. If it is, the
program prevents any overflow, keeping everything in check.
4. How to Run and Use the Program
First, save the code as [Link].
Next, open a terminal or command prompt in the folder where the saved the file.
Compile: javac [Link]
Run: javac StudentManagement
5. Using the Administrator Interface
Once you run the program, you'll be greeted with an administrative menu that offers several
options:
1. Add New Student
Here we will need to provide a unique ID, the student’s name, a positive age, and their
grade.
If the ID already exists or if the age is invalid, an error message will be seen.
2. Update existing Student Information by ID
Enter the ID of the student whose details you wish to update.
If the ID is found, it will display the current information.
We can either enter new values or just hit Enter to keep the existing ones.
Invalid age inputs will be caught and ignored, prompting an error message.
3. View Student Details by ID View All Students
Simply enter the student’s ID to retrieve their name, age, and grade.
If the ID doesn’t exist, an error message will be displayed.
4. View All Students
For view all, this option will show a list of all student records in the order they were
added.
5. Exit
This option allows you to safely close the program.
The program incorporates error handling and provides clear prompts to enhance user experience,
which is crucial for maintaining reliable student information systems and minimizing data-entry
errors (Patil et al., 2023; Marcel, 2019; Barot & Jain, 2025).
This implementation satisfies:
Private instance variables (Student class).
Private static variables and static management methods.
Menu-based administrator interface.
Error handling for invalid input and missing IDs.
Clear documentation and comments.
Output
Administrative Menu
Invalid and Error and out of range
Full Output Valid
References
Barot, N., & Jain, V. (2025). Design and Implementation of a Student Management Information
System (SMIS). International Scientific Journal of Engineering and Management.
[Link]
Eck, D. J. (2022). Introduction to programming using java version 9, JavaFX edition. Licensed.
under CC 4.0. [Link]
Patil, V., Patil, D., Satpute, H., & Tayade, S. (2023). Student Record Management System using
Django. International Journal for Research in Applied Science and Engineering
Technology. [Link]
using-django
Tang, Y. (2023). Design and Implementation of a Student Management System Based on
Springboot Framework Technology. Proceedings of the First International Conference
on Science, Engineering and Technology Practices for Sustainable Development,
ICSETPSD 2023, 17th-18th November 2023, Coimbatore, Tamilnadu, India
[Link]
Zhou, X. (2018). Design and Implementation of Student Information Management System Based
On Java. Proceedings of the 1st International Conference on Information Science and
Systems. [Link]