first commit
This commit is contained in:
@@ -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.
@@ -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"
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package org.palomafp.dam2.aadd.npz;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.npz.model.Continente;
|
||||||
|
import org.palomafp.dam2.aadd.npz.model.Pais;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
public static final String RUTA_FICHERO = "C:\\Users\\npauc\\aadd\\fic03\\informacion_paises.txt";
|
||||||
|
|
||||||
|
public static void main (String[] args) {
|
||||||
|
GestorMapaMundi app = new GestorMapaMundi();
|
||||||
|
|
||||||
|
int identificadorPais = 105;
|
||||||
|
Pais pais = app.obtenerPaisPorIdentificador(identificadorPais);
|
||||||
|
|
||||||
|
System.out.println(pais);
|
||||||
|
|
||||||
|
System.out.println("----------------------------------------------------");
|
||||||
|
|
||||||
|
String codigoContinente = "04";
|
||||||
|
List<Pais> listaPaises = app.obtenerPaisPorContinente(codigoContinente);
|
||||||
|
|
||||||
|
for (Pais pais2: listaPaises) {
|
||||||
|
System.out.println(pais2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais obtenerPaisPorIdentificador(int identificador) {
|
||||||
|
Pais paisEncontrado = null;
|
||||||
|
|
||||||
|
File f = new File(RUTA_FICHERO);
|
||||||
|
|
||||||
|
if(!f.exists()){
|
||||||
|
System.out.println("No encuentro el fichero " + f.getAbsolutePath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try(BufferedReader br = new BufferedReader(new FileReader(f))){
|
||||||
|
String linea;
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
linea = linea.trim();
|
||||||
|
if(linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] camposPais = linea.split(",");
|
||||||
|
String idPais = camposPais[1].trim();
|
||||||
|
|
||||||
|
|
||||||
|
if(Integer.parseInt(idPais) == identificador ) {
|
||||||
|
String codigoContinente = camposPais[0].trim().replace("\"","");
|
||||||
|
String nombrePais = camposPais[2].trim().replace("\"", "");
|
||||||
|
String capitalPais = camposPais[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
|
||||||
|
paisEncontrado = new Pais();
|
||||||
|
paisEncontrado.setIdentificador(Integer.parseInt(idPais));
|
||||||
|
paisEncontrado.setNombre(nombrePais);
|
||||||
|
paisEncontrado.setCapital(capitalPais);
|
||||||
|
paisEncontrado.setContinente(continente);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(IOException e) {
|
||||||
|
System.out.println("No se puede abrir el fichero: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return paisEncontrado;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<Pais> obtenerPaisPorContinente(String codContinente) {
|
||||||
|
|
||||||
|
List<Pais> listaPaisesEncontrados = null;
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
File fPaises = new File(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try(BufferedReader br = new BufferedReader(new FileReader(fPaises))){
|
||||||
|
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
linea = linea.trim();
|
||||||
|
if (linea.isEmpty() || linea.startsWith("#")){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] campoPais = linea.split(",");
|
||||||
|
|
||||||
|
String codigoContinente = campoPais[0].trim().replace("\"" , "");
|
||||||
|
|
||||||
|
if(codigoContinente.equals(codContinente)) {
|
||||||
|
|
||||||
|
if(listaPaisesEncontrados == null) {
|
||||||
|
listaPaisesEncontrados = new ArrayList<Pais>();
|
||||||
|
}
|
||||||
|
|
||||||
|
String idPais = campoPais[1].trim();
|
||||||
|
String nombrePais = campoPais[2].trim().replace("\"", "");
|
||||||
|
String capitalParis = campoPais[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(Integer.parseInt(idPais));
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capitalParis);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
listaPaisesEncontrados.add(pais);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (IOException e) {
|
||||||
|
System.out.println("" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaPaisesEncontrados;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.palomafp.dam2.aadd.npz.model;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo;
|
||||||
|
private String 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 + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.palomafp.dam2.aadd.npz.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public int getIdentificado() {
|
||||||
|
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 + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user