commit 6361d9ef9f8c5cb8d36d3b621cfb9443dcd5b894 Author: sheila-mb28 Date: Thu Sep 24 16:30:02 2026 +0200 Primer commit actividad 1.2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0e29e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Compilados de Java +*.class +bin/ + +# Configuración de Eclipse +.project +.classpath +.settings/ \ No newline at end of file diff --git a/src/org/palomafp/add/smmb/Fic02.java b/src/org/palomafp/add/smmb/Fic02.java new file mode 100644 index 0000000..fa32c3a --- /dev/null +++ b/src/org/palomafp/add/smmb/Fic02.java @@ -0,0 +1,63 @@ +package org.palomafp.add.smmb; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import org.palomafp.add.smmb.vo.Continente; +import org.palomafp.add.smmb.vo.Pais; + +public class Fic02 { + + public static void main(String[] args) { + + File paises = new File("D:/Documentos/DAM 2/AC - Acceso a Datos/Practicas/aadd/fic02/informacion_paises.txt"); + + imprimirInformacionPaises(paises); + + + } + + public static void imprimirInformacionPaises(File paises) { + + try { + + BufferedReader br = new BufferedReader(new FileReader(paises)); + + String linea = ""; + + while((linea = br.readLine()) != null) { + + if (!(linea.isEmpty() || linea.startsWith("#") || linea.startsWith("-"))){ + + String[] campos = linea.split(","); + + + String codContinente = campos[0].trim().replace("\"", ""); + int id = Integer.parseInt(campos[1].trim()); + String nombre = campos[2].trim().replace("\"", ""); + String capital = campos[3].trim().replace("\"", ""); + + + Continente continente = new Continente(codContinente); + Pais pais = new Pais(id, nombre, capital, continente); + + System.out.println(pais); + System.out.println("INSERT INTO T_PAIS VALUES (" + continente + ", " + id + ", " + nombre + ", " + capital + ");"); + + } + + } + + br.close(); + + } catch (IOException ioe) { + System.out.println(ioe.getMessage()); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + } + +} diff --git a/src/org/palomafp/add/smmb/vo/Continente.java b/src/org/palomafp/add/smmb/vo/Continente.java new file mode 100644 index 0000000..b32e990 --- /dev/null +++ b/src/org/palomafp/add/smmb/vo/Continente.java @@ -0,0 +1,39 @@ +package org.palomafp.add.smmb.vo; + +public class Continente { + + private String codigo; + private String nombre; + + public Continente(String codigo, String nombre) { + this.codigo = codigo; + this.nombre = nombre; + } + + public Continente(String codigo) { + this.codigo = codigo; + } + + + + 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/add/smmb/vo/Pais.java b/src/org/palomafp/add/smmb/vo/Pais.java new file mode 100644 index 0000000..ed612f6 --- /dev/null +++ b/src/org/palomafp/add/smmb/vo/Pais.java @@ -0,0 +1,49 @@ +package org.palomafp.add.smmb.vo; + +public class Pais { + + private int identificador; + private String nombre; + private String capital; + private Continente continente; + + 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; + } + + + + @Override + public String toString() { + return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + ", continente=" + + continente + "]"; + } + + + + +}