Console-Based Student Record Management with Java Arrays

Implement a student information system using Java SE with console I/O operasions. The solution applies object-oriented design patterns, separating entity definitions from controller logic while utiilzing static arrays for data persistence.

Define the domain model with private attributes and public interfaces:

class Learner {
    private String enrollmentId;
    private String fullName;
    private int yearsOld;
    private boolean isFemale;
    private double gradePoint;

    public Learner(String id, String name, int age, boolean female, double score) {
        this.enrollmentId = id;
        this.fullName = name;
        this.yearsOld = age;
        this.isFemale = female;
        this.gradePoint = score;
    }

    public String getEnrollmentId() { return enrollmentId; }
    public void setEnrollmentId(String id) { this.enrollmentId = id; }
    public String getFullName() { return fullName; }
    public void setFullName(String name) { this.fullName = name; }
    public int getYearsOld() { return yearsOld; }
    public void setYearsOld(int age) { this.yearsOld = age; }
    public boolean getIsFemale() { return isFemale; }
    public void setIsFemale(boolean female) { this.isFemale = female; }
    public double getGradePoint() { return gradePoint; }
    public void setGradePoint(double score) { this.gradePoint = score; }

    public void printDetails() {
        System.out.println("ID: " + enrollmentId);
        System.out.println("Name: " + fullName);
        System.out.println("Age: " + yearsOld);
        System.out.println("Gender: " + (isFemale ? "Female" : "Male"));
        System.out.println("Score: " + gradePoint);
    }
}

Create the management class with static array allocation and operational methods:

import java.util.Scanner;

public class AcademicRegistry {
    private static final int CAPACITY = 10;
    private static Learner[] roster = new Learner[CAPACITY];
    private static int activeCount = 0;
    private static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        int operation = -1;
        while (operation != 0) {
            renderMenu();
            operation = Integer.parseInt(input.nextLine());
            processSelection(operation);
        }
        input.close();
    }

    private static void renderMenu() {
        System.out.println("========================================");
        System.out.println("    Student Information System");
        System.out.println("========================================");
        System.out.println("1. Display All Records");
        System.out.println("2. Add New Student");
        System.out.println("3. Remove Student");
        System.out.println("4. Update Record");
        System.out.println("5. Search by ID");
        System.out.println("0. Exit");
        System.out.println("========================================");
        System.out.print("Select option: ");
    }

    private static void processSelection(int choice) {
        switch (choice) {
            case 1: listAllStudents(); break;
            case 2: registerNewStudent(); break;
            case 3: expungeRecord(); break;
            case 4: amendRecord(); break;
            case 5: locateStudent(); break;
            case 0: System.out.println("Terminating application..."); break;
            default: System.out.println("Invalid selection.");
        }
    }

    private static void registerNewStudent() {
        if (activeCount >= CAPACITY) {
            System.out.println("Error: Maximum capacity reached.");
            return;
        }

        System.out.print("Enter Student ID: ");
        String id = input.nextLine();
        
        if (locateIndexById(id) != -1) {
            System.out.println("Error: ID already exists.");
            return;
        }

        System.out.print("Enter Name: ");
        String name = input.nextLine();
        System.out.print("Enter Age: ");
        int age = Integer.parseInt(input.nextLine());
        System.out.print("Enter Gender (true=Female, false=Male): ");
        boolean gender = Boolean.parseBoolean(input.nextLine());
        System.out.print("Enter Score: ");
        double score = Double.parseDouble(input.nextLine());

        roster[activeCount] = new Learner(id, name, age, gender, score);
        activeCount++;
        System.out.println("Registration successful.");
    }

    private static void expungeRecord() {
        System.out.print("Enter ID to delete: ");
        String targetId = input.nextLine();
        int index = locateIndexById(targetId);
        
        if (index == -1) {
            System.out.println("Record not found.");
            return;
        }

        for (int i = index; i < activeCount - 1; i++) {
            roster[i] = roster[i + 1];
        }
        roster[activeCount - 1] = null;
        activeCount--;
        System.out.println("Deletion completed.");
    }

    private static void amendRecord() {
        System.out.print("Enter ID to modify: ");
        String targetId = input.nextLine();
        int index = locateIndexById(targetId);
        
        if (index == -1) {
            System.out.println("Record not found.");
            return;
        }

        System.out.print("Enter New ID: ");
        String newId = input.nextLine();
        System.out.print("Enter New Name: ");
        String newName = input.nextLine();
        System.out.print("Enter New Age: ");
        int newAge = Integer.parseInt(input.nextLine());
        System.out.print("Enter New Gender (true=Female, false=Male): ");
        boolean newGender = Boolean.parseBoolean(input.nextLine());
        System.out.print("Enter New Score: ");
        double newScore = Double.parseDouble(input.nextLine());

        roster[index] = new Learner(newId, newName, newAge, newGender, newScore);
        System.out.println("Update successful.");
    }

    private static void locateStudent() {
        System.out.print("Enter ID to search: ");
        String targetId = input.nextLine();
        int index = locateIndexById(targetId);
        
        if (index != -1) {
            roster[index].printDetails();
        } else {
            System.out.println("No matching record found.");
        }
    }

    private static void listAllStudents() {
        if (activeCount == 0) {
            System.out.println("No records available.");
            return;
        }
        for (int i = 0; i < activeCount; i++) {
            roster[i].printDetails();
            System.out.println("--------------------");
        }
    }

    private static int locateIndexById(String id) {
        for (int i = 0; i < activeCount; i++) {
            if (roster[i].getEnrollmentId().equals(id)) {
                return i;
            }
        }
        return -1;
    }
}

Tags: java Console Application CRUD array OOP

Posted on Sun, 07 Jun 2026 17:37:43 +0000 by RobbertvanOs