> For the complete documentation index, see [llms.txt](https://skilly.gitbook.io/java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://skilly.gitbook.io/java/ejercicios-4/soluciones/05-poo/05.1-poo-iniciacion/ejer05_poo1_solucion.md).

# \[Solución] Ejercicios básicos sobre POO

Espero que hayas conseguido resolver los ejercicios por ti mismo, pero si no, no te preocupes. Vamos a repasar el resultado para que puedas entender qué elementos eran necesarios y por qué.

## Ejercicio 1: Crear una Clase Libro

```java
public class Libro {
    // Propiedades
    private String titulo;
    private String autor;
    private int anioPublicacion;

    // Constructor
    public Libro(String titulo, String autor, int anioPublicacion) {
        this.titulo = titulo;
        this.autor = autor;
        this.anioPublicacion = anioPublicacion;
    }

    // Método para mostrar detalles
    public void mostrarDetalles() {
        System.out.println("Título: " + titulo + ", Autor: " + autor + ", Año de Publicación: " + anioPublicacion);
    }

    // Métodos getters y setters podrían añadirse aquí
}

class Main {
    public static void main(String[] args) {
        Libro libro = new Libro("El Quijote", "Miguel de Cervantes", 1605);
        libro.mostrarDetalles();
    }
}
```

## Sistema Básico de Gestión de Estudiantes

### Estudiante

```java
class Estudiante {
    // Propiedades
    private String nombre;
    private int edad;
    private String grado;

    // Constructor
    public Estudiante(String nombre, int edad, String grado) {
        this.nombre = nombre;
        this.edad = edad;
        this.grado = grado;
    }

    // Método para mostrar detalles
    public void mostrarDetalles() {
        System.out.println("Nombre: " + nombre + ", Edad: " + edad + ", Grado: " + grado);
    }
}
```

### Curso

```java
class Curso {
    // Propiedad
    private String nombreCurso;
    private ArrayList<Estudiante> estudiantes;

    // Constructor
    public Curso(String nombreCurso) {
        this.nombreCurso = nombreCurso;
        this.estudiantes = new ArrayList<>();
    }

    // Método para agregar estudiantes
    public void agregarEstudiante(Estudiante estudiante) {
        estudiantes.add(estudiante);
    }

    // Método para mostrar detalles de estudiantes
    public void mostrarEstudiantes() {
        System.out.println("Estudiantes del curso " + nombreCurso + ":");
        for (Estudiante estudiante : estudiantes) {
            estudiante.mostrarDetalles();
        }
    }
}
```

### Main

```java
class Main {
    public static void main(String[] args) {
        Estudiante estudiante1 = new Estudiante("Juan", 20, "2º de Bachillerato");
        Estudiante estudiante2 = new Estudiante("Ana", 19, "2º de Bachillerato");

        Curso curso = new Curso("Matemáticas Avanzadas");
        curso.agregarEstudiante(estudiante1);
        curso.agregarEstudiante(estudiante2);

        curso.mostrarEstudiantes();
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://skilly.gitbook.io/java/ejercicios-4/soluciones/05-poo/05.1-poo-iniciacion/ejer05_poo1_solucion.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
