Primer commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
bin/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.palomafp.aadd.ss.model;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
public Continente() {
|
||||||
|
}
|
||||||
|
|
||||||
|
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,42 @@
|
|||||||
|
package org.palomafp.aadd.ss.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
|
||||||
|
public Pais() {
|
||||||
|
}
|
||||||
|
|
||||||
|
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 + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package org.palomafp.dam2.aadd.ss;
|
||||||
|
|
||||||
|
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 org.palomafp.aadd.ss.model.Pais;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String ruta = "C:\\Users\\sajed\\Desktop\\2DAM\\AADD\\aadd\\fic03\\informacion_paises (2).txt";
|
||||||
|
File paises = new File(ruta);
|
||||||
|
|
||||||
|
Pais pais = obtenerPaisPorIdentificador(paises, 105);
|
||||||
|
System.out.println("Paises enconrado:");
|
||||||
|
System.out.println(pais);
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
List<Pais> listaPaises = obtnerPaisesPorCOntinente(paises, "04");
|
||||||
|
System.out.println("Paises del continente 04: ");
|
||||||
|
|
||||||
|
for(Pais p : listaPaises) {
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pais obtenerPaisPorIdentificador(File paises, int identificador) {
|
||||||
|
|
||||||
|
Pais pais = null;
|
||||||
|
try {
|
||||||
|
BufferedReader br = new BufferedReader(new FileReader(paises));
|
||||||
|
String linea;
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if((linea.isEmpty() || linea.startsWith("#"))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
linea = linea.replaceAll("\"","" );
|
||||||
|
String[] datos = linea.split(",");
|
||||||
|
|
||||||
|
String codigoContinente = datos[0].trim();
|
||||||
|
int idPais = Integer.parseInt(datos[1].trim());
|
||||||
|
String nombre = datos[2].trim();
|
||||||
|
String capital = datos[3].trim();
|
||||||
|
|
||||||
|
if(idPais == identificador) {
|
||||||
|
pais = new Pais();
|
||||||
|
|
||||||
|
pais.setIdentificador(idPais);
|
||||||
|
pais.setNombre(nombre);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Pais> obtnerPaisesPorCOntinente(File paises, String codigoContinente) {
|
||||||
|
List<Pais> listaPaises = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedReader br = new BufferedReader(new FileReader(paises));
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if(linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
linea = linea.replace("\"", "");
|
||||||
|
|
||||||
|
String[] datos = linea.split(",");
|
||||||
|
|
||||||
|
String codigo = datos[0].trim();
|
||||||
|
int identificador = Integer.parseInt(datos[1].trim());
|
||||||
|
String nombre = datos[2].trim();
|
||||||
|
String capital = datos[3].trim();
|
||||||
|
|
||||||
|
if(codigo.equals(codigoContinente)) {
|
||||||
|
Pais pais = new Pais();
|
||||||
|
|
||||||
|
pais.setIdentificador(identificador);
|
||||||
|
pais.setNombre(nombre);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
|
||||||
|
listaPaises.add(pais);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaPaises;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user