Primer Commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
bin/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.palomafp.aadd.aqv.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 "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package org.palomafp.aadd.aqv.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package org.palomafp.dam2.aadd.aqv;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.aqv.model.Continente;
|
||||||
|
import org.palomafp.aadd.aqv.model.Pais;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
private static final String RUTA_FICHERO = "C:\\Users\\aadd\\fic03\\informacion_paises.txt";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
System.out.println("--- RESULTADO APARTADO A (Identificador 105) ---");
|
||||||
|
|
||||||
|
Pais pais105 = obtenerPaisPorIdentificador(105);
|
||||||
|
|
||||||
|
if (pais105 != null) {
|
||||||
|
System.out.println(pais105);
|
||||||
|
} else {
|
||||||
|
System.out.println("No se ha encontrado ningún país con ese identificador.");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("\n--- RESULTADO APARTADO B (Continente 04) ---");
|
||||||
|
|
||||||
|
List<Pais> paisesContinente04 = obtenerPaisesPorContinente("04");
|
||||||
|
|
||||||
|
for (Pais p : paisesContinente04) {
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pais obtenerPaisPorIdentificador(int identificador) {
|
||||||
|
|
||||||
|
File fichero = new File(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if (linea.startsWith("#") || linea.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] datos = linea.replace("\"", "").split(",");
|
||||||
|
|
||||||
|
if (datos.length == 4) {
|
||||||
|
|
||||||
|
int idActual = Integer.parseInt(datos[1].trim());
|
||||||
|
|
||||||
|
if (idActual == identificador) {
|
||||||
|
|
||||||
|
Continente continente = new Continente(datos[0].trim(), null);
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
|
||||||
|
pais.setIdentificador(idActual);
|
||||||
|
pais.setNombre(datos[2].trim());
|
||||||
|
pais.setCapital(datos[3].trim());
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException | NumberFormatException e) {
|
||||||
|
|
||||||
|
System.err.println("Error procesando el fichero: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Pais> obtenerPaisesPorContinente(String codigoContinente) {
|
||||||
|
|
||||||
|
List<Pais> listaPaises = new ArrayList<>();
|
||||||
|
|
||||||
|
File fichero = new File(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
if (linea.startsWith("#") || linea.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] datos = linea.replace("\"", "").split(",");
|
||||||
|
|
||||||
|
if (datos.length == 4) {
|
||||||
|
|
||||||
|
String codigoActual = datos[0].trim();
|
||||||
|
|
||||||
|
if (codigoActual.equals(codigoContinente)) {
|
||||||
|
|
||||||
|
Continente continente = new Continente(codigoActual, null);
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
|
||||||
|
pais.setIdentificador(Integer.parseInt(datos[1].trim()));
|
||||||
|
|
||||||
|
pais.setNombre(datos[2].trim());
|
||||||
|
|
||||||
|
pais.setCapital(datos[3].trim());
|
||||||
|
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
listaPaises.add(pais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException | NumberFormatException e) {
|
||||||
|
|
||||||
|
System.err.println("Error procesando el fichero: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaPaises;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user