Primer commit
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
# Eclipse
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
|
||||
# Compilación Java
|
||||
bin/
|
||||
target/
|
||||
*.class
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Sistema operativo
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
@@ -0,0 +1,143 @@
|
||||
package org.palomafp.aadd.inm;
|
||||
|
||||
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.aadd.inm.model.Continente;
|
||||
import org.palomafp.aadd.inm.model.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* AppPrincipal: Clase que realiza el tratamiento de un fichero con información
|
||||
* de países.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 24 sept 2026
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorMapaMundi {
|
||||
|
||||
private static final String RUTA_FICHERO = "C:\\Users\\ineva\\INM\\tmp\\aadd\\fic03\\informacion_paises.txt";
|
||||
|
||||
public static void main(String[] args) {
|
||||
GestorMapaMundi app = new GestorMapaMundi();
|
||||
|
||||
int identificadorPais = 105;
|
||||
Pais pais = app.obtenerPaisPorIdentificador(identificadorPais);
|
||||
|
||||
// Imprimir la información del país en la consola.
|
||||
System.out.println(pais);
|
||||
|
||||
System.out.println("----------------------------------------------------");
|
||||
|
||||
String codigoContinente = "04";
|
||||
List<Pais> listaPaises = app.obtenerPaisesPorContinente(codigoContinente);
|
||||
// Imprimir la información de los paises en la consola.
|
||||
for (Pais pais2 : listaPaises) {
|
||||
System.out.println(pais2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Pais obtenerPaisPorIdentificador(int identificador) {
|
||||
Pais paisEncontrado = null;
|
||||
|
||||
File ficheroPaises = new File(RUTA_FICHERO);
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(ficheroPaises));
|
||||
while (reader.ready()) {
|
||||
String linea = reader.readLine();
|
||||
|
||||
// Nos saltamos las líneas que comienzan con el carácter #, que son comentarios.
|
||||
if (!linea.trim().startsWith("#")) {
|
||||
String[] camposPais = linea.split(",");
|
||||
|
||||
String idPais = camposPais[1].trim();
|
||||
// Comprobamos si el identificador del país coincide con el que estamos
|
||||
// buscando.
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return paisEncontrado;
|
||||
}
|
||||
|
||||
private List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||
List<Pais> listaPaisesEncontrados = null;
|
||||
|
||||
File ficheroPaises = new File(RUTA_FICHERO);
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(ficheroPaises));
|
||||
while (reader.ready()) {
|
||||
String linea = reader.readLine();
|
||||
|
||||
// Nos saltamos las líneas que comienzan con el carácter #, que son comentarios.
|
||||
if (!linea.trim().startsWith("#")) {
|
||||
String[] camposPais = linea.split(",");
|
||||
|
||||
String codigoContinente = camposPais[0].trim().replace("\"", "");
|
||||
if (codigoContinente.equals(codContinente)) {
|
||||
// La primera vez que entramos en este bloque, inicializamos la lista de países
|
||||
// encontrados.
|
||||
if (listaPaisesEncontrados == null) {
|
||||
listaPaisesEncontrados = new ArrayList<Pais>();
|
||||
}
|
||||
String idPais = camposPais[1].trim();
|
||||
String nombrePais = camposPais[2].trim().replace("\"", "");
|
||||
String capitalPais = camposPais[3].trim().replace("\"", "");
|
||||
|
||||
Continente continente = new Continente();
|
||||
continente.setCodigo(codigoContinente);
|
||||
|
||||
Pais pais = new Pais();
|
||||
pais.setIdentificador(Integer.parseInt(idPais));
|
||||
pais.setNombre(nombrePais);
|
||||
pais.setCapital(capitalPais);
|
||||
pais.setContinente(continente);
|
||||
|
||||
listaPaisesEncontrados.add(pais);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return listaPaisesEncontrados;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.palomafp.aadd.inm.model;
|
||||
|
||||
/**
|
||||
*
|
||||
* Continente: Clase que se asocia a la información de un continente.
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 24 sept 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
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,58 @@
|
||||
package org.palomafp.aadd.inm.model;
|
||||
|
||||
/**
|
||||
*
|
||||
* Pais Clase que se asocia a la información de un país.
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 24 sept 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class Pais {
|
||||
private int identificador;
|
||||
private String nombre;
|
||||
private String capital;
|
||||
|
||||
private 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 + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user