Java Student Management System Implementation

Classified in Computers

Written on in English with a size of 5.78 KB

Java Student Management System: Core Concepts

This document presents a foundational Java program designed to manage student data. It demonstrates key Object-Oriented Programming (OOP) principles through a simple console-based application.

Prerequisites

  • Basic understanding of Java programming.
  • Familiarity with classes, objects, methods, and variables.

Core Components of the Student System

The Aluno Class: Student Data Model

The Aluno class serves as the blueprint for creating student objects. Each object encapsulates a student's name, course, and a unique registration number.

Class Attributes

  • nome (String): Stores the student's name.
  • curso (String): Stores the student's enrolled course.
  • num_matricula (int): Represents the unique registration number (RA).
  • total_alunos (static int): A static counter to track the total number of students registered, used for generating unique RAs.

Constructor: Initializing Student Objects

The constructor of the Aluno class is responsible for collecting initial student information and assigning a unique registration number upon object creation.

public class Aluno {
    String nome, curso;
    int num_matricula;
    public static int total_alunos;
Aluno() {
    System.out.print("Nome: ");
    Scanner ler = new Scanner(System.in);
    nome = ler.nextLine();
    System.out.print("Curso: ");
    curso = ler.nextLine();
    num_matricula = 100000 + total_alunos + 1;
    total_alunos++;
    System.out.print("RA registrado: " + num_matricula + "\n");
}
// ... other methods

}

Method: alterarCurso() - Updating Student Course

This method allows for updating a student's enrolled course. It prompts the user for the new course name.

    void alterarCurso() {
System.out.print("Novo curso: ");
Scanner ler = new Scanner(System.in);
curso = ler.nextLine();
}

Method: toString() - Student Information Display

The toString() method provides a formatted string representation of the student's details, including their name, course, and registration number.

    public String toString() {
String matricula = ("O(a) aluno(a) " + nome + " está matriculado no curso " + curso + " e seu RA é " + num_matricula + "\n");
return matricula;
}
}

Main Program Logic: Student Management Application

The main method orchestrates the application's flow, providing a menu-driven interface for user interaction. It utilizes an array to store Aluno objects.

Import Statement

The Scanner class is used for reading user input, hence the necessary import statement.

import java.util.Scanner;

Application Entry Point (main method)

    public static void main(String[] args) {
int i = 0, op_menu, cod, j = 0, k = 0, aux = 0;
Aluno[] cadastro = new Aluno[5];
    do {
        System.out.println("********************* ");
        System.out.println("-1 Cadastrar Aluno: ");
        System.out.println("-2 Exibir Matrícula: ");
        System.out.println("-3 Alterar curso: ");
        System.out.println("-0 Sair: ");
        System.out.println("********************* ");
        System.out.print(" Opção: ");
        Scanner ler = new Scanner(System.in);
        op_menu = ler.nextInt();

        switch (op_menu) {
            case 1:
                cadastro[i] = new Aluno();
                i++;
                aux = i;
                break;
            case 2:
                System.out.print("Digite seu RA: ");
                cod = ler.nextInt();
                for (k = 0; k < aux; k++) {
                    if (cod == cadastro[k].num_matricula) {
                        System.out.print(cadastro[k]);
                        break;
                    }
                }
                break;
            case 3:
                System.out.print("Digite seu RA: ");
                cod = ler.nextInt();
                for (j = 0; j < aux; j++) {
                    if (cod == cadastro[j].num_matricula) {
                        cadastro[j].alterarCurso();
                        break;
                    }
                }
                if (j == aux) {
                    System.out.print("Número de cadastro não encontrado!\n");
                }
                break;
            case 0:
                System.out.println("Saindo do sistema...");
                break;
            default:
                System.out.println("Opção inválida. Tente novamente.");
        }
    } while (op_menu != 0);
}</code></pre><h3>Menu Options Explained</h3><ul><li><b>1 - Cadastrar Aluno:</b> Creates a new <code>Aluno</code> object, prompts for name and course, and assigns a unique RA.</li><li><b>2 - Exibir Matrícula:</b> Asks for a student's RA and displays their full details if found.</li><li><b>3 - Alterar Curso:</b> Prompts for a student's RA and allows updating their course if the RA is found.</li><li><b>0 - Sair:</b> Exits the application.</li></ul><h3>Error Handling</h3><p>The system includes basic error handling for invalid registration numbers when attempting to display or alter student data.</p><p>This program provides a clear example of how to structure a simple Java application using classes and objects for data management.</p>

Related entries: