commit 9d72a8232d033f719dfde57b9c9e171c45eeee1c Author: juanperoh11-lgtm. Date: Sun Sep 27 13:20:44 2026 +0200 Actividad 3 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..8e0cfed --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + Ficheros_03 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + 1790507968348 + + 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/model/Continente.class b/bin/org/palomafp/aadd/aez/model/Continente.class new file mode 100644 index 0000000..45b5e63 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..db2b2eb Binary files /dev/null and b/bin/org/palomafp/aadd/aez/model/Pais.class differ diff --git a/bin/org/palomafp/add/aez/GestorMapaMundi.class b/bin/org/palomafp/add/aez/GestorMapaMundi.class new file mode 100644 index 0000000..64d9ffb Binary files /dev/null and b/bin/org/palomafp/add/aez/GestorMapaMundi.class differ 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..4880fa5 --- /dev/null +++ b/src/org/palomafp/aadd/aez/model/Continente.java @@ -0,0 +1,34 @@ +package org.palomafp.aadd.aez.model; + +import java.io.Serializable; + +public class Continente implements Serializable { + 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..b81d6bd --- /dev/null +++ b/src/org/palomafp/aadd/aez/model/Pais.java @@ -0,0 +1,60 @@ +package org.palomafp.aadd.aez.model; + +import java.io.Serializable; + +public class Pais implements Serializable { + private int identificador; + private String nombre; + private String capital; + private Continente continente; + + // Constructor sin argumentos + public Pais() { + } + + public Pais(int identificador, String nombre, String capital, Continente continente) { + this.identificador = identificador; + this.nombre = nombre; + this.capital = capital; + this.continente = continente; + } + + // Getters y Setters + 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 getCapital() { + return capital; + } + + public void setCapital(String capital) { + this.capital = capital; + } + + public Continente getContinente() { + return continente; + } + + public void setContinente(Continente continente) { + this.continente = continente; + } + + @Override + public String toString() { + return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + ", continente=" + + (continente != null ? continente.getCodigo() : "N/A") + "]"; + } +} diff --git a/src/org/palomafp/add/aez/GestorMapaMundi.java b/src/org/palomafp/add/aez/GestorMapaMundi.java new file mode 100644 index 0000000..b5936f8 --- /dev/null +++ b/src/org/palomafp/add/aez/GestorMapaMundi.java @@ -0,0 +1,71 @@ +package org.palomafp.add.aez; + +import org.palomafp.aadd.aez.model.Continente; +import org.palomafp.aadd.aez.model.Pais; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +public class GestorMapaMundi { + + private static final String RUTA = "C:\\Users\\aleja\\aadd\\fic03\\informacion_paises.txt"; + + public static void main(String[] args) { + GestorMapaMundi gestor = new GestorMapaMundi(); + + } + + public Pais obtenerPaisPorId(int idPais) { + for (Pais p : cargarPaises()) { + if (p.getIdentificador() == idPais) { + return p; + } + } + return null; + } + + public List obtenerPaisesPorContinente(String codContinente) { + List resultado = new ArrayList<>(); + for (Pais p : cargarPaises()) { + if (p.getContinente().getCodigo().equals(codContinente)) { + resultado.add(p); + } + } + return resultado; + } + + private List cargarPaises() { + // Crea una lista vacía de tipo Pais donde se irán guardando todos los países + // que vayamos leyendo del fichero + List lista = new ArrayList<>(); + try { + // lee todas las líneas del fichero de golpe y las guarda en una lista de + // cadenas de texto + List lineas = Files.readAllLines(Paths.get(RUTA)); + for (String linea : lineas) { + linea = linea.trim(); + // Salta comentarios y líneas vacías + if (linea.isEmpty() || linea.startsWith("#")) { + continue; + } + + // Limpia comillas y separa por comas + String[] datos = linea.replace("\"", "").split(","); + + String codContinente = datos[0].trim(); + int id = Integer.parseInt(datos[1].trim()); + String nombre = datos[2].trim(); + String capital = datos[3].trim(); + + Continente c = new Continente(codContinente, ""); + Pais p = new Pais(id, nombre, capital, c); + lista.add(p); + } + } catch (Exception e) { + System.out.println("Error al leer el archivo: " + e.getMessage()); + } + return lista; + } +}