commit 8eb1c9f81a6de6f8ea9a883f6534e11411f54fc7 Author: alumnoT Date: Fri Sep 25 17:14:16 2026 +0200 1 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..4e29ea7 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.gitignore.txt b/.gitignore.txt new file mode 100644 index 0000000..e69de29 diff --git a/.project b/.project new file mode 100644 index 0000000..6308568 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Ficheros_02 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e4acff5 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=26 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=26 +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.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=26 diff --git a/bin/org/palomafp/aadd/rif/AppPrincipal.class b/bin/org/palomafp/aadd/rif/AppPrincipal.class new file mode 100644 index 0000000..6f8797b Binary files /dev/null and b/bin/org/palomafp/aadd/rif/AppPrincipal.class differ diff --git a/bin/org/palomafp/aadd/rif/vo/Continente.class b/bin/org/palomafp/aadd/rif/vo/Continente.class new file mode 100644 index 0000000..9b4242f Binary files /dev/null and b/bin/org/palomafp/aadd/rif/vo/Continente.class differ diff --git a/bin/org/palomafp/aadd/rif/vo/Pais.class b/bin/org/palomafp/aadd/rif/vo/Pais.class new file mode 100644 index 0000000..eb91656 Binary files /dev/null and b/bin/org/palomafp/aadd/rif/vo/Pais.class differ diff --git a/src/org/palomafp/aadd/rif/AppPrincipal.java b/src/org/palomafp/aadd/rif/AppPrincipal.java new file mode 100644 index 0000000..eb6a4e4 --- /dev/null +++ b/src/org/palomafp/aadd/rif/AppPrincipal.java @@ -0,0 +1,84 @@ +package org.palomafp.aadd.rif; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import org.palomafp.aadd.rif.vo.Continente; +import org.palomafp.aadd.rif.vo.Pais; + +public class AppPrincipal { + + public static void main(String[] args) { + // Sustituye "IsidoroNM" por tu ruta o usuario real según corresponda + String rutaFichero = "C:\\Users\\alumnoT\\aadd\\fic02.txt"; + + imprimirInformacionPaises(rutaFichero); + } + + public static void imprimirInformacionPaises(String ruta) { + File fichero = new File(ruta); + + if (!fichero.exists()) { + System.err.println("El fichero no existe en la ruta especificada: " + ruta); + return; + } + + try (BufferedReader br = new BufferedReader(new FileReader(fichero))) { + String linea; + + while ((linea = br.readLine()) != null) { + // Limpiar espacios en blanco al inicio y al final + linea = linea.trim(); + + // Las líneas vacías o aquellas que comienzan por # no se procesan ni imprimen + if (linea.isEmpty() || linea.startsWith("#")) { + continue; + } + + // Descomponer la línea. Supongamos separación por punto y coma ';' o coma ',' + // Ejemplo esperado de línea: 93;Arabia Saudita;Riad;03 + String[] datos = linea.split(","); + + if (datos.length >= 4) { + try { + String codContinente = datos[0].replace("\"", "").trim(); + String idStr = datos[1].replace("\"", "").trim(); + String nombrePais = datos[2].replace("\"", "").trim(); + String capital = datos[3].replace("\"", "").trim(); + + int id = Integer.parseInt(idStr); + + // Instanciamos el objeto Continente de acuerdo con la estructura solicitada + Continente continente = new Continente(); + continente.setCodigo(codContinente); + continente.setNombre(null); // Según la salida muestra: nombre=null + + // Instanciamos el objeto País (Bean) + Pais pais = new Pais(); + pais.setIdentificador(id); + pais.setNombre(nombrePais); + pais.setCapital(capital); + pais.setContinente(continente); + + // 1. Imprimir la representación de los objetos tipo Bean + System.out.println(pais.toString()); + + // 2. Imprimir la sentencia SQL correspondiente con el formato esperado + System.out.printf("INSERT INTO T_PAIS (cod_continente, identificador, capital, nombre_pais) VALUES (%d, '%s', '%s', '%s');\n", + pais.getIdentificador(), + pais.getContinente().getCodigo(), + pais.getCapital(), + pais.getNombre()); + + } catch (NumberFormatException e) { + System.err.println("Error de formato en el identificador numérico de la línea: " + linea); + } + } + } + + } catch (IOException e) { + System.err.println("Ocurrió un error al leer el fichero de datos: " + e.getMessage()); + } + } +} diff --git a/src/org/palomafp/aadd/rif/vo/Continente.java b/src/org/palomafp/aadd/rif/vo/Continente.java new file mode 100644 index 0000000..f125451 --- /dev/null +++ b/src/org/palomafp/aadd/rif/vo/Continente.java @@ -0,0 +1,37 @@ +package org.palomafp.aadd.rif.vo; + +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 + "]"; + } +} diff --git a/src/org/palomafp/aadd/rif/vo/Pais.java b/src/org/palomafp/aadd/rif/vo/Pais.java new file mode 100644 index 0000000..4bba096 --- /dev/null +++ b/src/org/palomafp/aadd/rif/vo/Pais.java @@ -0,0 +1,55 @@ +package org.palomafp.aadd.rif.vo; + +public class Pais { + private int identificador; + private String nombre; + private String capital; + private Continente continente; + + public Pais() { + } + + public Pais(int identificador, String nombre, String capital, Continente continente) { + this.identificador = identificador; + this.nombre = nombre; + this.capital = capital; + this.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 + "]"; + } +}