From f4717e8e651ac8e771b3f09fc0d80bc61eb708cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Ra=C3=BAl=20Quezada=20Valladares?= Date: Fri, 2 Oct 2026 17:28:25 +0200 Subject: [PATCH] Primer Commit --- .gitignore | 4 + src/org/palomafp/aadd/aqv/dao/IPaisDao.java | 9 ++ .../aadd/aqv/dao/imp/PaisDaoFichero.java | 75 ++++++++++ .../palomafp/aadd/aqv/model/Continente.java | 34 +++++ src/org/palomafp/aadd/aqv/model/Pais.java | 48 +++++++ .../dam2/aadd/aqv/GestorMapaMundi.java | 128 ++++++++++++++++++ 6 files changed, 298 insertions(+) create mode 100644 .gitignore create mode 100644 src/org/palomafp/aadd/aqv/dao/IPaisDao.java create mode 100644 src/org/palomafp/aadd/aqv/dao/imp/PaisDaoFichero.java create mode 100644 src/org/palomafp/aadd/aqv/model/Continente.java create mode 100644 src/org/palomafp/aadd/aqv/model/Pais.java create mode 100644 src/org/palomafp/dam2/aadd/aqv/GestorMapaMundi.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43e6c06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin/ +.settings/ +.classpath +.project \ No newline at end of file diff --git a/src/org/palomafp/aadd/aqv/dao/IPaisDao.java b/src/org/palomafp/aadd/aqv/dao/IPaisDao.java new file mode 100644 index 0000000..cefb88f --- /dev/null +++ b/src/org/palomafp/aadd/aqv/dao/IPaisDao.java @@ -0,0 +1,9 @@ +package org.palomafp.aadd.aqv.dao; + +import org.palomafp.aadd.aqv.model.Pais; +import java.util.List; + +public interface IPaisDao { + Pais obtenerPaisPorID(int idPais); + List obtenerPaisesPorContinente(String codContinente); +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/aqv/dao/imp/PaisDaoFichero.java b/src/org/palomafp/aadd/aqv/dao/imp/PaisDaoFichero.java new file mode 100644 index 0000000..f56d523 --- /dev/null +++ b/src/org/palomafp/aadd/aqv/dao/imp/PaisDaoFichero.java @@ -0,0 +1,75 @@ +package org.palomafp.aadd.aqv.dao.imp; + +import org.palomafp.aadd.aqv.dao.IPaisDao; +import org.palomafp.aadd.aqv.model.Continente; +import org.palomafp.aadd.aqv.model.Pais; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class PaisDaoFichero implements IPaisDao { + + private static final String RUTA_FICHERO = "C:\\Users\\alvar\\aadd\\fic04\\informacion_paises.txt"; + + public Pais obtenerPaisPorID(int idPais) { + File fichero = new File(RUTA_FICHERO); + try (BufferedReader br = new BufferedReader(new FileReader(fichero))) { + String linea; + while ((linea = br.readLine()) != null) { + if (linea.startsWith("#") || linea.trim().isEmpty()) { + continue; + } + String[] datos = linea.replace("\"", "").split(","); + if (datos.length == 4) { + int idActual = Integer.parseInt(datos[1].trim()); + if (idActual == idPais) { + Continente c = new Continente(datos[0].trim(), null); + Pais p = new Pais(); + p.setIdentificador(idActual); + p.setNombre(datos[2].trim()); + p.setNombreCapital(datos[3].trim()); + p.setContinente(c); + return p; + } + } + } + } catch (IOException | NumberFormatException e) { + System.err.println("Error procesando el fichero: " + e.getMessage()); + } + return null; + } + + @Override + public List obtenerPaisesPorContinente(String codContinente) { + List listaPaises = new ArrayList<>(); + File fichero = new File(RUTA_FICHERO); + try (BufferedReader br = new BufferedReader(new FileReader(fichero))) { + String linea; + while ((linea = br.readLine()) != null) { + if (linea.startsWith("#") || linea.trim().isEmpty()) { + continue; + } + String[] datos = linea.replace("\"", "").split(","); + if (datos.length == 4) { + String codActual = datos[0].trim(); + if (codActual.equals(codContinente)) { + Continente c = new Continente(codActual, null); + Pais p = new Pais(); + p.setIdentificador(Integer.parseInt(datos[1].trim())); + p.setNombre(datos[2].trim()); + p.setNombreCapital(datos[3].trim()); + p.setContinente(c); + listaPaises.add(p); + } + } + } + } catch (IOException | NumberFormatException e) { + System.err.println("Error procesando el fichero: " + e.getMessage()); + } + return listaPaises; + } +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/aqv/model/Continente.java b/src/org/palomafp/aadd/aqv/model/Continente.java new file mode 100644 index 0000000..042b47e --- /dev/null +++ b/src/org/palomafp/aadd/aqv/model/Continente.java @@ -0,0 +1,34 @@ +package org.palomafp.aadd.aqv.model; + +public class Continente { + private String codigo; + private String nombre; + + public Continente() {} + + public Continente(String codigo, String nombre) { + this.codigo = codigo; + this.nombre = nombre; + } + + public String getCodigo() { + return codigo; + } + + public void setCodigo(String codigo) { + this.codigo = codigo; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + @Override + public String toString() { + return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]"; + } +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/aqv/model/Pais.java b/src/org/palomafp/aadd/aqv/model/Pais.java new file mode 100644 index 0000000..a596120 --- /dev/null +++ b/src/org/palomafp/aadd/aqv/model/Pais.java @@ -0,0 +1,48 @@ +package org.palomafp.aadd.aqv.model; + +public class Pais { + private int identificador; + private String nombre; + private String nombreCapital; + private Continente continente; + + public Pais() {} + + public int getIdentificador() { + return identificador; + } + + public void setIdentificador(int identificador) { + this.identificador = identificador; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + public String getNombreCapital() { + return nombreCapital; + } + + public void setNombreCapital(String nombreCapital) { + this.nombreCapital = nombreCapital; + } + + public Continente getContinente() { + return continente; + } + + public void setContinente(Continente continente) { + this.continente = continente; + } + + @Override + public String toString() { + return "Pais [identificador=" + identificador + ", nombre=" + nombre + + ", nombreCapital=" + nombreCapital + ", continente=" + continente + "]"; + } +} \ No newline at end of file diff --git a/src/org/palomafp/dam2/aadd/aqv/GestorMapaMundi.java b/src/org/palomafp/dam2/aadd/aqv/GestorMapaMundi.java new file mode 100644 index 0000000..05b6af2 --- /dev/null +++ b/src/org/palomafp/dam2/aadd/aqv/GestorMapaMundi.java @@ -0,0 +1,128 @@ +package org.palomafp.dam2.aadd.aqv; + +import org.palomafp.aadd.aqv.model.Continente; +import org.palomafp.aadd.aqv.model.Pais; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class GestorMapaMundi { + + private static final String RUTA_FICHERO = "C:\\Users\\aadd\\fic03\\informacion_paises.txt"; + + public static void main(String[] args) { + + System.out.println("--- RESULTADO APARTADO A (Identificador 105) ---"); + + Pais pais105 = obtenerPaisPorIdentificador(105); + + if (pais105 != null) { + System.out.println(pais105); + } else { + System.out.println("No se ha encontrado ningún país con ese identificador."); + } + + System.out.println("\n--- RESULTADO APARTADO B (Continente 04) ---"); + + List paisesContinente04 = obtenerPaisesPorContinente("04"); + + for (Pais p : paisesContinente04) { + System.out.println(p); + } + } + + public static Pais obtenerPaisPorIdentificador(int identificador) { + + File fichero = new File(RUTA_FICHERO); + + try (BufferedReader br = new BufferedReader(new FileReader(fichero))) { + + String linea; + + while ((linea = br.readLine()) != null) { + + if (linea.startsWith("#") || linea.trim().isEmpty()) { + continue; + } + + String[] datos = linea.replace("\"", "").split(","); + + if (datos.length == 4) { + + int idActual = Integer.parseInt(datos[1].trim()); + + if (idActual == identificador) { + + Continente continente = new Continente(datos[0].trim(), null); + + Pais pais = new Pais(); + + pais.setIdentificador(idActual); + pais.setNombre(datos[2].trim()); + pais.setNombreCapital(datos[3].trim()); + pais.setContinente(continente); + + return pais; + } + } + } + + } catch (IOException | NumberFormatException e) { + + System.err.println("Error procesando el fichero: " + e.getMessage()); + } + + return null; + } + + public static List obtenerPaisesPorContinente(String codigoContinente) { + + List listaPaises = new ArrayList<>(); + + File fichero = new File(RUTA_FICHERO); + + try (BufferedReader br = new BufferedReader(new FileReader(fichero))) { + + String linea; + + while ((linea = br.readLine()) != null) { + if (linea.startsWith("#") || linea.trim().isEmpty()) { + continue; + } + String[] datos = linea.replace("\"", "").split(","); + + if (datos.length == 4) { + + String codigoActual = datos[0].trim(); + + if (codigoActual.equals(codigoContinente)) { + + Continente continente = new Continente(codigoActual, null); + + Pais pais = new Pais(); + + pais.setIdentificador(Integer.parseInt(datos[1].trim())); + + pais.setNombre(datos[2].trim()); + + pais.setNombreCapital(datos[3].trim()); + + pais.setContinente(continente); + + listaPaises.add(pais); + } + } + } + + } catch (IOException | NumberFormatException e) { + + System.err.println("Error procesando el fichero: " + e.getMessage()); + } + + return listaPaises; + } +}