Primer commit
This commit is contained in:
@@ -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/jdk-27">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Fichero_05</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>
|
||||||
|
</projectDescription>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=26
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=26
|
||||||
|
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.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=26
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
module Fichero_03 {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.palomafp.aadd.lmga.dao;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.lmga.model.Pais;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
Pais obtenerPaisPorID(int idPais);
|
||||||
|
List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package org.palomafp.aadd.lmga.dao.impl;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.lmga.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.lmga.model.Continente;
|
||||||
|
import org.palomafp.aadd.lmga.model.Pais;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PaisDaoFichero implements IPaisDAO {
|
||||||
|
|
||||||
|
private static final String fichero_paises = "C:\\Users\\alumnoT\\aadd\\fic05\\informacion_paises.txt";
|
||||||
|
|
||||||
|
private static final String fichero_continentes = "C:\\Users\\alumnoT\\aadd\\fic05\\informacion_continentes.csv";
|
||||||
|
|
||||||
|
|
||||||
|
private Map<String, Continente> mapContinentes;
|
||||||
|
|
||||||
|
public PaisDaoFichero() {
|
||||||
|
this.mapContinentes = new HashMap<>();
|
||||||
|
cargarContinentes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cargarContinentes() {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(fichero_continentes))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = reader.readLine()) != null) {
|
||||||
|
linea = linea.trim();
|
||||||
|
if (linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] partes = linea.split("#");
|
||||||
|
if (partes.length >= 2) {
|
||||||
|
String cod = partes[1].replace("\"", "").trim();
|
||||||
|
String nombre = partes[2].replace("\"", "").trim();
|
||||||
|
mapContinentes.put(cod, new Continente(cod, nombre));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error al leer el fichero de continentes: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPaisPorID(int idPais) {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(fichero_paises))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = reader.readLine()) != null) {
|
||||||
|
linea = linea.trim();
|
||||||
|
if (linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pais pais = lineaAPais(linea);
|
||||||
|
if (pais != null && pais.getIdentificador() == idPais) {
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error al leer el fichero de países: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||||
|
List<Pais> resultados = new ArrayList<>();
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(fichero_paises))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = reader.readLine()) != null) {
|
||||||
|
linea = linea.trim();
|
||||||
|
if (linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pais pais = lineaAPais(linea);
|
||||||
|
if (pais != null && pais.getContinente() != null &&
|
||||||
|
codContinente.equals(pais.getContinente().getCodigo())) {
|
||||||
|
resultados.add(pais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error al leer el fichero de países: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return resultados;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pais lineaAPais(String linea) {
|
||||||
|
String[] partes = linea.split(",");
|
||||||
|
if (partes.length < 4) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String codContinente = partes[0].replace("\"", "").trim();
|
||||||
|
int id = Integer.parseInt(partes[1].trim());
|
||||||
|
String nombrePais = partes[2].replace("\"", "").trim();
|
||||||
|
String capital = partes[3].replace("\"", "").trim();
|
||||||
|
|
||||||
|
|
||||||
|
Continente continente = mapContinentes.getOrDefault(codContinente, new Continente(codContinente, "Desconocido"));
|
||||||
|
|
||||||
|
return new Pais(id, nombrePais, capital, continente);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.palomafp.aadd.lmga.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 "("+this.codigo+")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package org.palomafp.aadd.lmga.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public Pais() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais(int identificador, String nombre, String capital, Continente continente) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.capital = capital;
|
||||||
|
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 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() {
|
||||||
|
|
||||||
|
String nombreContinente = (this.continente != null && this.continente.getNombre() != null)
|
||||||
|
? this.continente.getNombre() : "Desconocido";
|
||||||
|
String codigoContinente = (this.continente != null && this.continente.getCodigo() != null)
|
||||||
|
? this.continente.getCodigo() : "Desconocido";
|
||||||
|
|
||||||
|
|
||||||
|
return this.nombre + " (" + this.identificador + ") con capital en " + this.capital +
|
||||||
|
" pertenece al continente " + nombreContinente + " (" + codigoContinente + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.palomafp.dam2.aadd.lmga;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.lmga.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.lmga.dao.impl.PaisDaoFichero;
|
||||||
|
import org.palomafp.aadd.lmga.model.Pais;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
private static final IPaisDAO paisDAO = new PaisDaoFichero();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("A: Obtener país con identificador 105\n");
|
||||||
|
Pais paisObtenido = obtenerPaisesPorIdentificador(105);
|
||||||
|
if (paisObtenido != null) {
|
||||||
|
System.out.println(paisObtenido);
|
||||||
|
} else {
|
||||||
|
System.out.println("No se encontró ningún país con ese identificador.");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("\nB: Obtener países del continente '04' \n");
|
||||||
|
List<Pais> listaPaises = obtenerListaPaisesPorContinente("04");
|
||||||
|
if (!listaPaises.isEmpty()) {
|
||||||
|
for (Pais p : listaPaises) {
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("No se encontraron países para el continente especificado.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pais obtenerPaisesPorIdentificador(int identificador) {
|
||||||
|
return paisDAO.obtenerPaisPorID(identificador);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Pais> obtenerListaPaisesPorContinente(String codContinente) {
|
||||||
|
return paisDAO.obtenerPaisesPorContinente(codContinente);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
anyo#codigo_continente#nombre_continente
|
||||||
|
2026#01# África
|
||||||
|
2026#02 #América
|
||||||
|
2026#03#Asia
|
||||||
|
2026# 04#Europa
|
||||||
|
2026#05#Oceanía
|
||||||
|
@@ -0,0 +1,23 @@
|
|||||||
|
# Información de países
|
||||||
|
# Se muestra información del código de continente, identificador de país, nombre del país junto con su capital
|
||||||
|
"01",1, "Angola", "Luanda"
|
||||||
|
"02",62, "Brasil", "Brasilia"
|
||||||
|
"02",63, "Canadá", "Ottawa"
|
||||||
|
"02",64, "Chile", "Santiago De Chile"
|
||||||
|
"02",65, "Colombia", "Bogotá"
|
||||||
|
# Otra lista de países
|
||||||
|
"03",92, "Afganistán", "Kabul"
|
||||||
|
"03",93, "Arabia Saudita", "Riad"
|
||||||
|
"03",105, "Filipinas", "Manila"
|
||||||
|
"03",106, "India", "Nueva Delhi"
|
||||||
|
"03",136, "Vietnam", "Hanoi"
|
||||||
|
"04",147, "Bulgaria", "Sofía"
|
||||||
|
"04",152, "España", "Madrid"
|
||||||
|
"04",181, "Suecia", "Estocolmo"
|
||||||
|
# La parte final de países
|
||||||
|
"04",182, "Suiza", "Berna"
|
||||||
|
"05",185, "Australia", "Canberra"
|
||||||
|
"05",186, "Fiyi", "Suva"
|
||||||
|
"05",187, "Islas Marshall", "Majuro"
|
||||||
|
"05",196, "Tonga", "Nuku'alofa"
|
||||||
|
"05",197, "Tuvalu", "Funafuti"
|
||||||
Reference in New Issue
Block a user