commit d13573cf5928990ad5ac044f30c4b8724f20253e Author: juanperoh11-lgtm. Date: Thu Oct 1 12:31:41 2026 +0200 Actividad 4 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..efedf92 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..2b80ec4 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + Ficheros_04 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + 1790850610473 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3124684 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=25 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=25 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=25 diff --git a/bin/org/palomafp/aadd/aez/GestorMapaMundi.class b/bin/org/palomafp/aadd/aez/GestorMapaMundi.class new file mode 100644 index 0000000..3a3d056 Binary files /dev/null and b/bin/org/palomafp/aadd/aez/GestorMapaMundi.class differ diff --git a/bin/org/palomafp/aadd/aez/dao/IPaisDAO.class b/bin/org/palomafp/aadd/aez/dao/IPaisDAO.class new file mode 100644 index 0000000..5afdebc Binary files /dev/null and b/bin/org/palomafp/aadd/aez/dao/IPaisDAO.class differ diff --git a/bin/org/palomafp/aadd/aez/dao/impl/PaisDaoFichero.class b/bin/org/palomafp/aadd/aez/dao/impl/PaisDaoFichero.class new file mode 100644 index 0000000..8444668 Binary files /dev/null and b/bin/org/palomafp/aadd/aez/dao/impl/PaisDaoFichero.class differ diff --git a/bin/org/palomafp/aadd/aez/model/Continente.class b/bin/org/palomafp/aadd/aez/model/Continente.class new file mode 100644 index 0000000..5c8f4ac Binary files /dev/null and b/bin/org/palomafp/aadd/aez/model/Continente.class differ diff --git a/bin/org/palomafp/aadd/aez/model/Pais.class b/bin/org/palomafp/aadd/aez/model/Pais.class new file mode 100644 index 0000000..5607eef Binary files /dev/null and b/bin/org/palomafp/aadd/aez/model/Pais.class differ diff --git a/src/org/palomafp/aadd/aez/GestorMapaMundi.java b/src/org/palomafp/aadd/aez/GestorMapaMundi.java new file mode 100644 index 0000000..ccc2559 --- /dev/null +++ b/src/org/palomafp/aadd/aez/GestorMapaMundi.java @@ -0,0 +1,41 @@ +package org.palomafp.aadd.aez; + +import java.util.List; +import org.palomafp.aadd.aez.dao.IPaisDAO; +import org.palomafp.aadd.aez.dao.impl.PaisDaoFichero; +import org.palomafp.aadd.aez.model.Pais; + +public class GestorMapaMundi { + + private static IPaisDAO paisDao = new PaisDaoFichero(); + + public static void main(String[] args) { + System.out.println("=== BÚSQUEDA POR IDENTIFICADOR ==="); + int idBuscar = 152; + Pais pais = obtenerPaisPorIdentificador(idBuscar); + + if (pais != null) { + System.out.println("País encontrado: " + pais.getNombre() + " | Capital: " + pais.getNombreCapital() + + " | Continente: " + pais.getContinente().getCodigo()); + } else { + System.out.println("No se encontró ningún país con ID " + idBuscar); + } + + System.out.println("\n=== BÚSQUEDA POR CONTINENTE ==="); + String codContinente = "04"; + List listaPaises = obtenerListaPaisesPorContinente(codContinente); + + System.out.println("Países en el continente " + codContinente + ": " + listaPaises.size()); + for (Pais p : listaPaises) { + System.out.println(" - " + p.getNombre() + " (Capital: " + p.getNombreCapital() + ")"); + } + } + + public static Pais obtenerPaisPorIdentificador(int identificadorPais) { + return paisDao.obtenerPaisPorIdentificador(identificadorPais); + } + + public static List obtenerListaPaisesPorContinente(String codContinente) { + return paisDao.obtenerPaisesPorContinente(codContinente); + } +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/aez/dao/IPaisDAO.java b/src/org/palomafp/aadd/aez/dao/IPaisDAO.java new file mode 100644 index 0000000..a7894e9 --- /dev/null +++ b/src/org/palomafp/aadd/aez/dao/IPaisDAO.java @@ -0,0 +1,10 @@ +package org.palomafp.aadd.aez.dao; + +import java.util.List; +import org.palomafp.aadd.aez.model.Pais; + +public interface IPaisDAO { + Pais obtenerPaisPorIdentificador(int idPais); + + List obtenerPaisesPorContinente(String codContinente); +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/aez/dao/impl/PaisDaoFichero.java b/src/org/palomafp/aadd/aez/dao/impl/PaisDaoFichero.java new file mode 100644 index 0000000..cb6f603 --- /dev/null +++ b/src/org/palomafp/aadd/aez/dao/impl/PaisDaoFichero.java @@ -0,0 +1,78 @@ +package org.palomafp.aadd.aez.dao.impl; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.palomafp.aadd.aez.dao.IPaisDAO; +import org.palomafp.aadd.aez.model.Continente; +import org.palomafp.aadd.aez.model.Pais; + +public class PaisDaoFichero implements IPaisDAO { + private String rutaFichero = "C:\\Users\\aleja\\aadd\\fic04\\informacion_paises.txt"; + + public PaisDaoFichero() { + } + + public PaisDaoFichero(String rutaFichero) { + this.rutaFichero = rutaFichero; + } + + @Override + public Pais obtenerPaisPorIdentificador(int idPais) { + List todos = cargarTodosLosPaises(); + for (Pais p : todos) { + if (p.getIdentificador() == idPais) { + return p; + } + } + return null; + } + + @Override + public List obtenerPaisesPorContinente(String codContinente) { + List resultado = new ArrayList<>(); + List todos = cargarTodosLosPaises(); + for (Pais p : todos) { + if (p.getContinente() != null && codContinente.equals(p.getContinente().getCodigo())) { + resultado.add(p); + } + } + return resultado; + } + + private List cargarTodosLosPaises() { + List lista = new ArrayList<>(); + + try (BufferedReader br = new BufferedReader(new FileReader(rutaFichero))) { + String linea; + + while ((linea = br.readLine()) != null) { + linea = linea.trim(); + if (linea.isEmpty() || linea.startsWith("#")) { + continue; + } + + String[] partes = linea.split(","); + if (partes.length >= 4) { + String codContinente = partes[0].trim().replace("\"", ""); + int id = Integer.parseInt(partes[1].trim()); + String nombrePais = partes[2].trim().replace("\"", ""); + String nombreCapital = partes[3].trim().replace("\"", ""); + + Continente continente = new Continente(codContinente, ""); + Pais pais = new Pais(id, nombrePais, nombreCapital, continente); + + lista.add(pais); + } + } + + } catch (IOException e) { + System.out.println(e.getMessage()); + } + return lista; + } + +} diff --git a/src/org/palomafp/aadd/aez/model/Continente.java b/src/org/palomafp/aadd/aez/model/Continente.java new file mode 100644 index 0000000..e49d36f --- /dev/null +++ b/src/org/palomafp/aadd/aez/model/Continente.java @@ -0,0 +1,30 @@ +package org.palomafp.aadd.aez.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; + } +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/aez/model/Pais.java b/src/org/palomafp/aadd/aez/model/Pais.java new file mode 100644 index 0000000..17363de --- /dev/null +++ b/src/org/palomafp/aadd/aez/model/Pais.java @@ -0,0 +1,50 @@ +package org.palomafp.aadd.aez.model; + +public class Pais { + private int identificador; + private String nombre; + private String nombreCapital; + private Continente continente; + + public Pais() { + } + + public Pais(int identificador, String nombre, String nombreCapital, Continente continente) { + this.identificador = identificador; + this.nombre = nombre; + this.nombreCapital = nombreCapital; + this.continente = continente; + } + + 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; + } +} \ No newline at end of file