Skip to main content

Overview

The logica package contains the business logic layer with two primary data model classes: Alumno (Student) and Cursos (Courses). These POJOs (Plain Old Java Objects) follow the JavaBeans pattern with private fields and public getters/setters.

Alumno

Student information and credentials

Cursos

Course enrollment data

Alumno Class

Represents a student’s personal information and authentication credentials.

Class Definition

logica/Alumno.java
package logica;

public class Alumno {
    private String nombre, apellido, contraseña, dni;
    
    public Alumno() {  
    }

    public Alumno(String nombre, String apellido, String contraseña, String dni) {
        this.nombre = nombre;
        this.apellido = apellido;
        this.contraseña = contraseña;
        this.dni = dni;
    }
}

Properties

Type: StringDescription: Student’s first nameGetter:
public String getNombre() {
    return nombre;
}
Setter:
public void setNombre(String nombre) {
    this.nombre = nombre;
}

Constructors

1

Default Constructor

Creates an empty Alumno instance:
public Alumno() {}
Used in the Registrar frame:
igu/Registrar.java:10
Alumno alu = new Alumno();
2

Parameterized Constructor

Initializes all fields:
public Alumno(String nombre, String apellido, String contraseña, String dni) {
    this.nombre = nombre;
    this.apellido = apellido;
    this.contraseña = contraseña;
    this.dni = dni;
}

Usage Example

From the Registrar frame, student data is collected via text field listeners:
igu/Registrar.java:180
private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {
    String nombre = txtNombre.getText();
    alu.setNombre(nombre);
}

private void txtApellidoActionPerformed(java.awt.event.ActionEvent evt) {
    String apellido = txtApellido.getText();
    alu.setApellido(apellido);
}

private void txtDniActionPerformed(java.awt.event.ActionEvent evt) {
    String dni = txtDni.getText();
    alu.setDni(dni);
}

private void txtContraActionPerformed(java.awt.event.ActionEvent evt) {
    String contra = txtContra.getText();
    alu.setContraseña(contra);
}
The action listeners trigger when the user presses Enter in each field, providing real-time data binding to the Alumno object. However, the main registration logic reads directly from the text fields to ensure all data is captured even if Enter wasn’t pressed.

Cursos Class

Represents a student’s course selections across five subject areas.

Class Definition

logica/Cursos.java
package logica;

public class Cursos {
    String matematica, historia, ciencias, literatura, civica;
    
    public Cursos() {
    }
    
    public Cursos(String matematica, String historia, String ciencias, 
                  String literatura, String civica) {
        this.matematica = matematica;
        this.historia = historia;
        this.ciencias = ciencias;
        this.literatura = literatura;
        this.civica = civica;
    }
}
Fields are declared with package-private access (no modifier), though getters and setters are public.

Course Properties

Each property stores the full course selection string including professor, room, and schedule:
Type: StringExample Value: "Matematica| Prof. Raúl Hernandez | A0504 | Lun y Mie 2:00pm a 4:00pm"
public String getMatematica() {
    return matematica;
}

public void setMatematica(String matematica) {
    this.matematica = matematica;
}

String Representation

The class overrides toString() for debugging and logging:
logica/Cursos.java:58
@Override
public String toString() {
    return "Cursos{" + 
        "matematica=" + matematica + 
        ", historia=" + historia + 
        ", ciencias=" + ciencias + 
        ", literatura=" + literatura + 
        ", civica=" + civica + 
        '}';
}
Example Output:
Cursos{matematica=Matematica| Prof. Raúl Hernandez | A0504 | Lun y Mie 2:00pm a 4:00pm, historia=Historia| Prof. Marisol Mercede | A0304 | Lun 10:00am a 1:00pm, ciencias=Ninguno, literatura=Ninguno, civica=Ninguno}

Usage in Matricula Frame

Course objects are created and managed in an ArrayList:
igu/Matricula.java:12
ArrayList<Cursos> listaCursos = new ArrayList<>();
When the student clicks “Agregar cursos”:
igu/Matricula.java:413
private void btnMatematicasActionPerformed(java.awt.event.ActionEvent evt) {
    Cursos curso = new Cursos();
    curso.setMatematica(scrMatematica.getSelectedItem().toString());
    curso.setHistoria(scrHistoria.getSelectedItem().toString());
    curso.setLiteratura(scrLiteratura.getSelectedItem().toString());
    curso.setCivica(scrCivica.getSelectedItem().toString());
    curso.setCiencias(scrCiencias.getSelectedItem().toString());
    listaCursos.add(curso);
    refrescarTabla();
}
Each Cursos object stores a complete set of five course selections, even if some are set to “Ninguno” (None).

Data Flow Diagram

Design Patterns

JavaBeans Pattern

Both classes follow the JavaBeans specification:
1

Private Fields

All data is encapsulated with private (or package-private) access modifiers
2

No-Argument Constructor

Both classes provide a default constructor for instantiation
3

Getter/Setter Methods

Public methods provide controlled access to properties
4

Serializable (Optional)

While not implemented here, JavaBeans typically implement Serializable for persistence

Data Transfer Objects (DTOs)

These classes act as DTOs, transferring data between the presentation layer (GUI frames) and the business logic layer:
ClassSourceDestinationPurpose
AlumnoRegistrar formLogin frameAuthentication
CursosMatricula dropdownsJTable displayCourse enrollment

Data Storage

Currently, the application uses in-memory storage:
No Persistence: Student and course data is lost when the application closes. All data exists only in Java objects during runtime.

Current Storage Mechanism

  • Created in Registrar frame
  • Passed to Login via constructor parameters
  • Not persisted beyond the session
igu/Registrar.java:222
log = new Login(dni, contra);

Potential Enhancements

For production use, consider adding:
  • JDBC: Connect to MySQL, PostgreSQL, or SQLite
  • JPA/Hibernate: Object-relational mapping
  • Serialization: Save objects to files
Example table structure:
CREATE TABLE alumnos (
    id INT PRIMARY KEY AUTO_INCREMENT,
    nombre VARCHAR(100),
    apellido VARCHAR(100),
    dni VARCHAR(20) UNIQUE,
    contraseña_hash VARCHAR(255)
);

CREATE TABLE cursos_matriculados (
    id INT PRIMARY KEY AUTO_INCREMENT,
    alumno_id INT,
    matematica TEXT,
    historia TEXT,
    ciencias TEXT,
    literatura TEXT,
    civica TEXT,
    fecha_matricula TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (alumno_id) REFERENCES alumnos(id)
);

Field Validation

Neither data model class includes built-in validation. Validation is performed in the GUI layer:

Alumno Validation (in Registrar)

igu/Registrar.java:212
if (nombre.isEmpty()) {
    JOptionPane.showMessageDialog(this, "COMPLETE SU NOMBRE", 
        "Advertencia", JOptionPane.WARNING_MESSAGE);
} else if (apellido.isEmpty()) {
    JOptionPane.showMessageDialog(this, "COMPLETE SU APELLIDO", 
        "Advertencia", JOptionPane.WARNING_MESSAGE);
} else if (dni.isEmpty()) {
    JOptionPane.showMessageDialog(this, "COMPLETE SU DNI", 
        "Advertencia", JOptionPane.WARNING_MESSAGE);
} else if (contra.isEmpty()) {
    JOptionPane.showMessageDialog(this, "COMPLETE SU CONTRASEÑA", 
        "Advertencia", JOptionPane.WARNING_MESSAGE);
}
Improvement Opportunity: Move validation logic into the model classes for better separation of concerns and reusability.

Class Diagram

Best Practices

Encapsulation

Private fields with public accessors protect data integrity

Constructor Overloading

Multiple constructors provide flexibility in object creation

toString Override

Custom string representation aids debugging

Immutability Consideration

Consider making fields final and removing setters for immutable objects

Next Steps

Architecture Overview

Return to the main architecture overview to see how these models fit into the complete system

Build docs developers (and LLMs) love