segundo commit
This commit is contained in:
parent
7de069f2d5
commit
7330361cfd
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-25">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
|
||||
2
.project
2
.project
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Actividad1_1</name>
|
||||
<name>Actividad1_3</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
package es.palomafp.aadd.inm;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* AppPrincipalPaises: Clase que procesa el fichero con información de países
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 26 sept 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class AppPrincipalPaises {
|
||||
|
||||
public static void main(String[] args) {
|
||||
AppPrincipalPaises app = new AppPrincipalPaises();
|
||||
|
||||
String rutaFichero = "C:\\Users\\ineva\\aadd\\inm\\act11\\informacion_paises.txt";
|
||||
app.procesarFicheroPaises(rutaFichero);
|
||||
}
|
||||
|
||||
private void procesarFicheroPaises(String rutaFichero) {
|
||||
try (BufferedReader bf = new BufferedReader(new FileReader(rutaFichero))) {
|
||||
String linea;
|
||||
while ((linea = bf.readLine()) != null) {
|
||||
|
||||
// Procesa las líneas que NO empeiecen por '--' ni por '#'
|
||||
if (!(linea.startsWith("--") || linea.startsWith("#"))) {
|
||||
// Procesar información del País
|
||||
String[] camposPais= linea.split(",");
|
||||
String codContinente=camposPais[0].trim();
|
||||
String identificador=camposPais[1].trim();
|
||||
String nombrePais=camposPais[2].trim();
|
||||
String capital=camposPais[3].trim(); ;
|
||||
|
||||
// Composición de la sentencia a imprimir
|
||||
String sentencia = String.format("INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES (%s,%s,%s,%s);",
|
||||
codContinente, identificador, nombrePais, capital);
|
||||
|
||||
System.out.println(sentencia);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("Fichero no encontrado: " + rutaFichero);
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al leer el fichero: " + rutaFichero);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
123
src/es/palomafp/aadd/inm/GestorMapaMundi.java
Normal file
123
src/es/palomafp/aadd/inm/GestorMapaMundi.java
Normal file
@ -0,0 +1,123 @@
|
||||
package es.palomafp.aadd.inm;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import es.palomafp.aadd.inm.vo.Continente;
|
||||
import es.palomafp.aadd.inm.vo.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorMapaMundi: Clase que procesa el fichero con información de países y
|
||||
* continentes
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 26 sept 2025
|
||||
*/
|
||||
|
||||
public class GestorMapaMundi {
|
||||
private final static String RUTA_FICHERO_PAISES = "C:\\Users\\IsidoroNM.A13PROFESOR\\aadd\\inm\\act13\\informacion_paises.txt";
|
||||
private final static String RUTA_FICHERO_CONTINENTES = "C:\\Users\\IsidoroNM.A13PROFESOR\\aadd\\inm\\act13\\informacion_continentes.csv";
|
||||
|
||||
public static void main(String[] args) {
|
||||
String codigoContinente = args[0];
|
||||
|
||||
GestorMapaMundi app = new GestorMapaMundi();
|
||||
|
||||
Continente continente = app.obtenerContinente(codigoContinente);
|
||||
// System.out.println(continente);
|
||||
|
||||
List<Pais> listPaises = app.obtenerListaPaises(codigoContinente);
|
||||
// System.out.println(listPaises);
|
||||
|
||||
for (Pais pais : listPaises) {
|
||||
if (pais.getNombre().startsWith("S")) {
|
||||
String informacionPais= "%s, capital de %s – %d, pertenece al continente %s (%s)";
|
||||
informacionPais=String.format(informacionPais, pais.getCapital(), pais.getNombre(), pais.getIdentificador(), pais.getContinente().getNombre(), pais.getContinente().getCodigo());
|
||||
System.out.println(informacionPais);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Continente obtenerContinente(String codigoContinente) {
|
||||
Continente continente = null;
|
||||
try (BufferedReader bf = new BufferedReader(new FileReader(RUTA_FICHERO_CONTINENTES))) {
|
||||
String linea;
|
||||
bf.readLine(); // Saltamos la línea de cabecera.
|
||||
while ((linea = bf.readLine()) != null) {
|
||||
|
||||
// Procesar información del Continente
|
||||
String[] camposContinente = linea.split("\\|");
|
||||
String codContinente = camposContinente[0].trim().replace("\"", "");
|
||||
String nombreContinente = camposContinente[1].trim().replace("\"", "");
|
||||
|
||||
if (codigoContinente != null && codigoContinente.equals(codContinente)) {
|
||||
// Se crea objeto continente cuando coincide con el código
|
||||
continente = new Continente();
|
||||
continente.setCodigo(codigoContinente);
|
||||
continente.setNombre(nombreContinente);
|
||||
}
|
||||
}
|
||||
} catch (
|
||||
|
||||
FileNotFoundException e) {
|
||||
System.err.println("Fichero no encontrado: " + RUTA_FICHERO_CONTINENTES);
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al leer el fichero: " + RUTA_FICHERO_CONTINENTES);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return continente;
|
||||
}
|
||||
|
||||
private List<Pais> obtenerListaPaises(String codigoContinente) {
|
||||
List<Pais> listaPaises = null;
|
||||
|
||||
try (BufferedReader bf = new BufferedReader(new FileReader(RUTA_FICHERO_PAISES))) {
|
||||
String linea;
|
||||
listaPaises =new ArrayList<Pais>();
|
||||
Continente continente = null;
|
||||
|
||||
while ((linea = bf.readLine()) != null) {
|
||||
|
||||
// Procesa las líneas que NO empeiecen por '--' ni por '#'
|
||||
if (!(linea.startsWith("--") || linea.startsWith("#"))) {
|
||||
// Procesar información del País
|
||||
String[] camposPais = linea.split(",");
|
||||
String codContinente = camposPais[0].trim().replace("\"", "");
|
||||
String identificador = camposPais[1].trim();
|
||||
String nombrePais = camposPais[2].trim().replace("\"", "");
|
||||
String capital = camposPais[3].trim().replace("\"", "");
|
||||
|
||||
if (codigoContinente.equals(codContinente)) {
|
||||
if (continente==null) {
|
||||
continente= obtenerContinente(codigoContinente);
|
||||
}
|
||||
Pais pais =new Pais();
|
||||
pais.setIdentificador(Integer.parseInt(identificador));
|
||||
pais.setNombre(nombrePais);
|
||||
pais.setCapital(capital);
|
||||
pais.setContinente(continente);
|
||||
|
||||
listaPaises.add(pais);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("Fichero no encontrado: " + RUTA_FICHERO_PAISES);
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al leer el fichero: " + RUTA_FICHERO_PAISES);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return listaPaises;
|
||||
}
|
||||
|
||||
}
|
||||
35
src/es/palomafp/aadd/inm/vo/Continente.java
Normal file
35
src/es/palomafp/aadd/inm/vo/Continente.java
Normal file
@ -0,0 +1,35 @@
|
||||
package es.palomafp.aadd.inm.vo;
|
||||
|
||||
/**
|
||||
* Continente: Clase que se encarga de almacenar información de un Continente.
|
||||
*
|
||||
* @author: Isidoro Nevares Martín (IES Virgen de la Paloma)
|
||||
* @date: 2 oct 2025
|
||||
*/
|
||||
public class Continente {
|
||||
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Continente [codigo=" + codigo + ", 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;
|
||||
}
|
||||
|
||||
}
|
||||
52
src/es/palomafp/aadd/inm/vo/Pais.java
Normal file
52
src/es/palomafp/aadd/inm/vo/Pais.java
Normal file
@ -0,0 +1,52 @@
|
||||
package es.palomafp.aadd.inm.vo;
|
||||
|
||||
/**
|
||||
* Pais: Clase que se encarga de almacenar información de un País.
|
||||
*
|
||||
* @author: Isidoro Nevares Martín (IES Virgen de la Paloma)
|
||||
* @date: 2 oct 2025
|
||||
*/
|
||||
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 + "]\n";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user