Actividad 3

This commit is contained in:
juanperoh11-lgtm.
2026-09-27 13:20:44 +02:00
commit 9d72a8232d
10 changed files with 216 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-25">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Ficheros_03</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1790507968348</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
+11
View File
@@ -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
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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;
}
}
+60
View File
@@ -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") + "]";
}
}
@@ -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<Pais> obtenerPaisesPorContinente(String codContinente) {
List<Pais> resultado = new ArrayList<>();
for (Pais p : cargarPaises()) {
if (p.getContinente().getCodigo().equals(codContinente)) {
resultado.add(p);
}
}
return resultado;
}
private List<Pais> cargarPaises() {
// Crea una lista vacía de tipo Pais donde se irán guardando todos los países
// que vayamos leyendo del fichero
List<Pais> lista = new ArrayList<>();
try {
// lee todas las líneas del fichero de golpe y las guarda en una lista de
// cadenas de texto
List<String> 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;
}
}