primer commit
This commit is contained in:
commit
076e04ad4f
10
.classpath
Normal file
10
.classpath
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/bin/
|
||||
*.class
|
||||
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Actividad1_4</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
13
.settings/org.eclipse.jdt.core.prefs
Normal file
13
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,13 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=24
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=24
|
||||
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=24
|
||||
44
src/es/palomafp/aadd/inm/GestorMapaMundi.java
Normal file
44
src/es/palomafp/aadd/inm/GestorMapaMundi.java
Normal file
@ -0,0 +1,44 @@
|
||||
package es.palomafp.aadd.inm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import es.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||
import es.palomafp.aadd.inm.dao.IPaisDAO;
|
||||
import es.palomafp.aadd.inm.dao.impl.ContinenteDaoCSV;
|
||||
import es.palomafp.aadd.inm.dao.impl.PaisDaoTXT;
|
||||
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 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String codigoContinente = args[0];
|
||||
|
||||
IContinenteDAO iContinenteDAO = new ContinenteDaoCSV();
|
||||
Continente continente = iContinenteDAO.obtenerContinente(codigoContinente);
|
||||
System.out.println(continente);
|
||||
|
||||
IPaisDAO iPaisDAO = new PaisDaoTXT();
|
||||
List<Pais> listPaises = iPaisDAO.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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
src/es/palomafp/aadd/inm/dao/IContinenteDAO.java
Normal file
14
src/es/palomafp/aadd/inm/dao/IContinenteDAO.java
Normal file
@ -0,0 +1,14 @@
|
||||
package es.palomafp.aadd.inm.dao;
|
||||
|
||||
import es.palomafp.aadd.inm.vo.Continente;
|
||||
|
||||
/**
|
||||
*
|
||||
* IContinenteDAO: Interfaz que contiene las operaciones a realizar sobre un continente
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 2 oct 2025
|
||||
*/
|
||||
public interface IContinenteDAO {
|
||||
Continente obtenerContinente(String codigoContinente);
|
||||
}
|
||||
16
src/es/palomafp/aadd/inm/dao/IPaisDAO.java
Normal file
16
src/es/palomafp/aadd/inm/dao/IPaisDAO.java
Normal file
@ -0,0 +1,16 @@
|
||||
package es.palomafp.aadd.inm.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import es.palomafp.aadd.inm.vo.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* IPaisDAO: Clase que ....
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 2 oct 2025
|
||||
*/
|
||||
public interface IPaisDAO {
|
||||
List<Pais> obtenerListaPaises(String codigoContinente);
|
||||
}
|
||||
57
src/es/palomafp/aadd/inm/dao/impl/ContinenteDaoCSV.java
Normal file
57
src/es/palomafp/aadd/inm/dao/impl/ContinenteDaoCSV.java
Normal file
@ -0,0 +1,57 @@
|
||||
package es.palomafp.aadd.inm.dao.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import es.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||
import es.palomafp.aadd.inm.vo.Continente;
|
||||
|
||||
/**
|
||||
*
|
||||
* ContinenteDaoCSV: Clase que implementa las operaciones del interfaz IPaisDAO
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 2 oct 2025
|
||||
*/
|
||||
public class ContinenteDaoCSV implements IContinenteDAO{
|
||||
private final static String RUTA_FICHERO_CONTINENTES = "C:\\Users\\IsidoroNM\\AADD\\inm\\act14\\informacion_continentes.csv";
|
||||
|
||||
private File fichero = new File(RUTA_FICHERO_CONTINENTES);
|
||||
|
||||
@Override
|
||||
public Continente obtenerContinente(String codigoContinente) {
|
||||
Continente continente = null;
|
||||
try (BufferedReader bf = new BufferedReader(new FileReader(fichero))) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
74
src/es/palomafp/aadd/inm/dao/impl/PaisDaoTXT.java
Normal file
74
src/es/palomafp/aadd/inm/dao/impl/PaisDaoTXT.java
Normal file
@ -0,0 +1,74 @@
|
||||
package es.palomafp.aadd.inm.dao.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
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.dao.IContinenteDAO;
|
||||
import es.palomafp.aadd.inm.dao.IPaisDAO;
|
||||
import es.palomafp.aadd.inm.vo.Continente;
|
||||
import es.palomafp.aadd.inm.vo.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* PaisDaoTXT: Clase que implementa las operaciones del interfaz IPaisDAO
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 2 oct 2025
|
||||
*/
|
||||
public class PaisDaoTXT implements IPaisDAO {
|
||||
private final static String RUTA_FICHERO_PAISES = "C:\\Users\\IsidoroNM\\AADD\\inm\\act14\\informacion_paises.txt";
|
||||
|
||||
private File fichero = new File(RUTA_FICHERO_PAISES);
|
||||
|
||||
@Override
|
||||
public List<Pais> obtenerListaPaises(String codigoContinente) {
|
||||
List<Pais> listaPaises = null;
|
||||
|
||||
try (BufferedReader bf = new BufferedReader(new FileReader(fichero))) {
|
||||
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) {
|
||||
IContinenteDAO iContinenteDAO = new ContinenteDaoCSV();
|
||||
continente = iContinenteDAO.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