primer commit
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
|
||||
*.class
|
||||
bin/
|
||||
target/
|
||||
out/
|
||||
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
*.iws
|
||||
*.ipr
|
||||
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
|
||||
Thumbs.db
|
||||
.DS_Store
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
module Ficheros_03 {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.palomafp.dam2.aadd.jx.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Continente implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
|
||||
public Continente() {
|
||||
}
|
||||
|
||||
public Continente(String codigo, String nombre) {
|
||||
this.codigo = codigo;
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
// Getters y Setters
|
||||
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,60 @@
|
||||
package org.palomafp.dam2.aadd.jx.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Pais implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int identificador;
|
||||
private String nombre;
|
||||
private String capital;
|
||||
private String codigoContinente;
|
||||
|
||||
public Pais() {
|
||||
}
|
||||
|
||||
public Pais(int identificador, String nombre, String capital, String codigoContinente) {
|
||||
this.identificador = identificador;
|
||||
this.nombre = nombre;
|
||||
this.capital = capital;
|
||||
this.codigoContinente = codigoContinente;
|
||||
}
|
||||
|
||||
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 String getCodigoContinente() {
|
||||
return codigoContinente;
|
||||
}
|
||||
|
||||
public void setCodigoContinente(String codigoContinente) {
|
||||
this.codigoContinente = codigoContinente;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pais [identificador=" + identificador + ", nombre=" + nombre +
|
||||
", capital=" + capital + ", codigoContinente=" + codigoContinente + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package org.palomafp.dam2.aadd.jxu;
|
||||
|
||||
import org.palomafp.dam2.aadd.jx.model.Pais;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
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";
|
||||
|
||||
|
||||
private static List<Pais> cargarPaisesDesdeFichero() {
|
||||
List<Pais> listaPaises = new ArrayList<>();
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(RUTA_FICHERO))) {
|
||||
String linea;
|
||||
while ((linea = br.readLine()) != null) {
|
||||
linea = linea.trim();
|
||||
|
||||
if (linea.isEmpty() || linea.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] campos = linea.split(",");
|
||||
if (campos.length == 4) {
|
||||
String codContinente = campos[0].replace("\"", "").trim();
|
||||
int id = Integer.parseInt(campos[1].trim());
|
||||
String nombre = campos[2].replace("\"", "").trim();
|
||||
String capital = campos[3].replace("\"", "").trim();
|
||||
|
||||
Pais pais = new Pais(id, nombre, capital, codContinente);
|
||||
listaPaises.add(pais);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al leer el archivo de texto: " + e.getMessage());
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Error al parsear el ID del país: " + e.getMessage());
|
||||
}
|
||||
|
||||
return listaPaises;
|
||||
}
|
||||
|
||||
|
||||
public static Pais obtenerPaisPorId(int identificador) {
|
||||
List<Pais> paises = cargarPaisesDesdeFichero();
|
||||
for (Pais p : paises) {
|
||||
if (p.getIdentificador() == identificador) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Pais> obtenerPaisesPorContinente(String codigoContinente) {
|
||||
List<Pais> resultado = new ArrayList<>();
|
||||
List<Pais> paises = cargarPaisesDesdeFichero();
|
||||
for (Pais p : paises) {
|
||||
if (p.getCodigoContinente().equalsIgnoreCase(codigoContinente)) {
|
||||
resultado.add(p);
|
||||
}
|
||||
}
|
||||
return resultado;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("prueba b: obtener País (ID = 105)");
|
||||
Pais pais105 = obtenerPaisPorId(105);
|
||||
if (pais105 != null) {
|
||||
System.out.println(pais105);
|
||||
} else {
|
||||
System.out.println("No se encontró ningún país con el ID 105.");
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
|
||||
System.out.println("pruiba b: obtener Lista de Países (Continente = '04')");
|
||||
List<Pais> paisesContinente04 = obtenerPaisesPorContinente("04");
|
||||
if (!paisesContinente04.isEmpty()) {
|
||||
for (Pais p : paisesContinente04) {
|
||||
System.out.println(p);
|
||||
}
|
||||
} else {
|
||||
System.out.println("No se encontraron países para el continente '04'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user