From a0015e0a8ee89f539927e6a36488eba3accc29b5 Mon Sep 17 00:00:00 2001 From: SASI Date: Sun, 27 Sep 2026 14:22:24 +0200 Subject: [PATCH] Primer commit --- .gitignore | 4 + .../palomafp/aadd/ss/model/Continente.java | 32 +++++ src/org/palomafp/aadd/ss/model/Pais.java | 42 ++++++ .../dam2/aadd/ss/GestorMapaMundi.java | 131 ++++++++++++++++++ 4 files changed, 209 insertions(+) create mode 100644 .gitignore create mode 100644 src/org/palomafp/aadd/ss/model/Continente.java create mode 100644 src/org/palomafp/aadd/ss/model/Pais.java create mode 100644 src/org/palomafp/dam2/aadd/ss/GestorMapaMundi.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43e6c06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin/ +.settings/ +.classpath +.project \ No newline at end of file diff --git a/src/org/palomafp/aadd/ss/model/Continente.java b/src/org/palomafp/aadd/ss/model/Continente.java new file mode 100644 index 0000000..c8625a0 --- /dev/null +++ b/src/org/palomafp/aadd/ss/model/Continente.java @@ -0,0 +1,32 @@ +package org.palomafp.aadd.ss.model; + +public class Continente { + + private String codigo; + private String nombre; + + public Continente() { + } + + 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 "Continente [codigo=" + codigo + + ", nombre=" + nombre + "]"; + } +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/ss/model/Pais.java b/src/org/palomafp/aadd/ss/model/Pais.java new file mode 100644 index 0000000..a155c04 --- /dev/null +++ b/src/org/palomafp/aadd/ss/model/Pais.java @@ -0,0 +1,42 @@ +package org.palomafp.aadd.ss.model; + +public class Pais { + + private int identificador; + private String nombre; + private String capital; + + public Pais() { + } + + 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; + } + + @Override + public String toString() { + return "Pais [identificador=" + identificador + + ", nombre=" + nombre + + ", capital=" + capital + "]"; + } +} \ No newline at end of file diff --git a/src/org/palomafp/dam2/aadd/ss/GestorMapaMundi.java b/src/org/palomafp/dam2/aadd/ss/GestorMapaMundi.java new file mode 100644 index 0000000..5e7b45f --- /dev/null +++ b/src/org/palomafp/dam2/aadd/ss/GestorMapaMundi.java @@ -0,0 +1,131 @@ +package org.palomafp.dam2.aadd.ss; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.palomafp.aadd.ss.model.Pais; + +public class GestorMapaMundi { + + public static void main(String[] args) { + + String ruta = "C:\\Users\\sajed\\Desktop\\2DAM\\AADD\\aadd\\fic03\\informacion_paises (2).txt"; + File paises = new File(ruta); + + Pais pais = obtenerPaisPorIdentificador(paises, 105); + System.out.println("Paises enconrado:"); + System.out.println(pais); + + System.out.println(); + + List listaPaises = obtnerPaisesPorCOntinente(paises, "04"); + System.out.println("Paises del continente 04: "); + + for(Pais p : listaPaises) { + System.out.println(p); + } + + + } + + public static Pais obtenerPaisPorIdentificador(File paises, int identificador) { + + Pais pais = null; + try { + BufferedReader br = new BufferedReader(new FileReader(paises)); + String linea; + while((linea = br.readLine()) != null) { + + if((linea.isEmpty() || linea.startsWith("#"))) { + continue; + } + + linea = linea.replaceAll("\"","" ); + String[] datos = linea.split(","); + + String codigoContinente = datos[0].trim(); + int idPais = Integer.parseInt(datos[1].trim()); + String nombre = datos[2].trim(); + String capital = datos[3].trim(); + + if(idPais == identificador) { + pais = new Pais(); + + pais.setIdentificador(idPais); + pais.setNombre(nombre); + pais.setCapital(capital); + + break; + } + + + } + + + br.close(); + + + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return pais; + + } + + + public static List obtnerPaisesPorCOntinente(File paises, String codigoContinente) { + List listaPaises = new ArrayList<>(); + + try { + BufferedReader br = new BufferedReader(new FileReader(paises)); + + String linea; + + while((linea = br.readLine()) != null) { + + if(linea.isEmpty() || linea.startsWith("#")) { + continue; + } + + linea = linea.replace("\"", ""); + + String[] datos = linea.split(","); + + String codigo = datos[0].trim(); + int identificador = Integer.parseInt(datos[1].trim()); + String nombre = datos[2].trim(); + String capital = datos[3].trim(); + + if(codigo.equals(codigoContinente)) { + Pais pais = new Pais(); + + pais.setIdentificador(identificador); + pais.setNombre(nombre); + pais.setCapital(capital); + + listaPaises.add(pais); + } + + } + + br.close(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return listaPaises; + + } + + +}