commit 94d6c6d99e551bdc2b140e7d6b9a979586f07d58 Author: Ricardo Carlos Escobar Soliz <“cescobar@educa.madrid.org”> Date: Sun Sep 27 03:14:13 2026 +0200 ejercicio3 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..52f234a --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.project b/.project new file mode 100644 index 0000000..97928c3 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Ficheros_03 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + 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..6f94d6a --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=23 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=23 +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=23 diff --git a/bin/org/palomafp/dam2/aadd/rces/AppPrincipal.class b/bin/org/palomafp/dam2/aadd/rces/AppPrincipal.class new file mode 100644 index 0000000..54e9727 Binary files /dev/null and b/bin/org/palomafp/dam2/aadd/rces/AppPrincipal.class differ diff --git a/bin/org/palomafp/dam2/aadd/rces/model/Continente.class b/bin/org/palomafp/dam2/aadd/rces/model/Continente.class new file mode 100644 index 0000000..550f1d2 Binary files /dev/null and b/bin/org/palomafp/dam2/aadd/rces/model/Continente.class differ diff --git a/bin/org/palomafp/dam2/aadd/rces/model/Pais.class b/bin/org/palomafp/dam2/aadd/rces/model/Pais.class new file mode 100644 index 0000000..2d26434 Binary files /dev/null and b/bin/org/palomafp/dam2/aadd/rces/model/Pais.class differ diff --git a/src/org/palomafp/dam2/aadd/rces/AppPrincipal.java b/src/org/palomafp/dam2/aadd/rces/AppPrincipal.java new file mode 100644 index 0000000..b244e1e --- /dev/null +++ b/src/org/palomafp/dam2/aadd/rces/AppPrincipal.java @@ -0,0 +1,108 @@ +package org.palomafp.dam2.aadd.rces; + +import java.io.BufferedReader; +import java.io.FileReader; + +import java.util.ArrayList; +import java.util.Scanner; + +import org.palomafp.dam2.aadd.rces.model.Continente; +import org.palomafp.dam2.aadd.rces.model.Pais; + +public class AppPrincipal { + + public static void main(String[] args) { + + try { + Scanner sc = new Scanner(System.in); + BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\ricardo\\aadd\\fic03\\informacion_paises.txt")); + ArrayList continentes = new ArrayList<>(); + ArrayList paises = new ArrayList<>(); + String linea; + while((linea = br.readLine()) != null) { + if(!linea.startsWith("#") && !linea.startsWith("--")) { + String infoDatos[] = linea.replace("\"", "\'").split(","); + + String codigoContinente = infoDatos[0]; + int identificadorPais = Integer.parseInt(infoDatos[1]); + String nombrePais = infoDatos[2]; + String nombreCapital = infoDatos[3]; + Continente continente = new Continente(codigoContinente, null); + + continentes.add(continente); + paises.add(new Pais(identificadorPais,nombrePais,nombreCapital,continente)); + } + + } + int menu; + do { + System.out.println("1. Pulsa 1 para buscar pais por el identificador \n2. Pulsa 2 para enseñar los paises que tiene el continente con el codigo"); + System.out.println("escriba -1 si quiere salir de la app"); + menu = sc.nextInt(); + + switch(menu) { + case 1 : + System.out.println("escriba el identificador "); + int identificador = sc.nextInt(); + obtenerPais(identificador,paises); + break; + case 2: + sc.nextLine(); + System.out.println("escriba el codigo del continente"); + + String codigo = sc.nextLine(); + + ArrayListpaisesContinente = new ArrayList<>(); + paisesContinente = obtenerPaisesContinente(codigo,paises); + System.out.println("el continente con el codigo "+codigo+" tiene estos paises"); + for(int i = 0; i < paisesContinente.size();i++){ + System.out.println(paisesContinente.get(i).toString()); + } + break; + case -1: + System.out.println("saliendo..."); + break; + default: + System.out.println("te has equivocado"); + } + + }while(menu != -1); + + }catch( Exception e) { + System.out.println("error"); + + } + + } + + public static void obtenerPais(int identificador,ArrayListpaises) { + + for(int i = 0; i < paises.size(); i++) { + + if(paises.get(i).getIdentificador() == (identificador)) { + + System.out.println(paises.get(i).toString()); + + break; + } + + } + + + } + + public static ArrayList obtenerPaisesContinente(String codigo ,ArrayList paises){ + + + ArrayList paisesContinente = new ArrayList<>(); + for(int i = 0; i < paises.size(); i++) { + if(paises.get(i).getContinente().getCodigo().replace("\'", "").equals(codigo)) { + paisesContinente.add(paises.get(i)); + } + } + + + return paisesContinente; + } + +} diff --git a/src/org/palomafp/dam2/aadd/rces/model/Continente.java b/src/org/palomafp/dam2/aadd/rces/model/Continente.java new file mode 100644 index 0000000..eda5118 --- /dev/null +++ b/src/org/palomafp/dam2/aadd/rces/model/Continente.java @@ -0,0 +1,28 @@ +package org.palomafp.dam2.aadd.rces.model; + +public class Continente { + private String codigo; + private String nombre; + public Continente(String codigo, String nombre) { + super(); + 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 "Continente [codigo=" + codigo + ", nombre=" + nombre + "]"; + } + +} diff --git a/src/org/palomafp/dam2/aadd/rces/model/Pais.java b/src/org/palomafp/dam2/aadd/rces/model/Pais.java new file mode 100644 index 0000000..0be351d --- /dev/null +++ b/src/org/palomafp/dam2/aadd/rces/model/Pais.java @@ -0,0 +1,52 @@ +package org.palomafp.dam2.aadd.rces.model; + +public class Pais { + private int identificador ; + private String nombre; + private String capital; + private Continente continente; + public Pais(int identificador, String nombre, String capital, Continente continente) { + super(); + 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() { + return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + ", continente=" + + continente + "]"; + } + + + + + + + + +}