Actividad 4
This commit is contained in:
+10
@@ -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>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Ficheros_04</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>1790850610473</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
|
||||
@@ -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.
Binary file not shown.
Binary file not shown.
@@ -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<Pais> 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<Pais> obtenerListaPaisesPorContinente(String codContinente) {
|
||||
return paisDao.obtenerPaisesPorContinente(codContinente);
|
||||
}
|
||||
}
|
||||
@@ -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<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||
}
|
||||
@@ -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<Pais> todos = cargarTodosLosPaises();
|
||||
for (Pais p : todos) {
|
||||
if (p.getIdentificador() == idPais) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||
List<Pais> resultado = new ArrayList<>();
|
||||
List<Pais> todos = cargarTodosLosPaises();
|
||||
for (Pais p : todos) {
|
||||
if (p.getContinente() != null && codContinente.equals(p.getContinente().getCodigo())) {
|
||||
resultado.add(p);
|
||||
}
|
||||
}
|
||||
return resultado;
|
||||
}
|
||||
|
||||
private List<Pais> cargarTodosLosPaises() {
|
||||
List<Pais> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user