Primer commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package org.palomafp.dam2.aadd.tma;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.palomafp.dam2.aadd.tma.model.Continente;
|
||||
import org.palomafp.dam2.aadd.tma.model.Pais;
|
||||
|
||||
public class GestorMapaMundi {
|
||||
|
||||
|
||||
|
||||
public static Pais obtenerPaisId(int id, ArrayList<Pais> lista) {
|
||||
for (int i = 0; i < lista.size(); i++) {
|
||||
if (lista.get(i).getIdentificador() == id) {
|
||||
return lista.get(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ArrayList<Pais> obtenerListaPaisPorContinente(String codCon, ArrayList<Pais> lista) {
|
||||
ArrayList<Pais> listaPaisCon = new ArrayList<Pais>();
|
||||
for (int i = 0; i < lista.size(); i++) {
|
||||
if (lista.get(i).getContinente().getCodigo() == codCon) {
|
||||
listaPaisCon.add(lista.get(i));
|
||||
}
|
||||
}
|
||||
return listaPaisCon;
|
||||
}
|
||||
public static Continente obtenerConPorCod (String cod, ArrayList<Continente> lista) {
|
||||
for (int i = 0; i < lista.size(); i++) {
|
||||
if (lista.get(i).getCodigo().equals(cod)) {
|
||||
return lista.get(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.palomafp.dam2.aadd.tma;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.palomafp.dam2.aadd.tma.model.Continente;
|
||||
import org.palomafp.dam2.aadd.tma.model.Pais;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\alumnoT\\aadd\\fic03\\informacion_paises.txt"));
|
||||
String linea;
|
||||
String[] datos;
|
||||
ArrayList<Continente> listaCon = new ArrayList<Continente>();
|
||||
listaCon.add(new Continente("01", "Africa"));
|
||||
listaCon.add(new Continente("02", "America"));
|
||||
listaCon.add(new Continente("03", "Asia"));
|
||||
listaCon.add(new Continente("04", "Europa"));
|
||||
listaCon.add(new Continente("05", "Oceania"));
|
||||
ArrayList<Pais> listaPais = new ArrayList<Pais>();
|
||||
while((linea = bfr.readLine()) != null) {
|
||||
if (!linea.startsWith("#") && !linea.startsWith("-")) {
|
||||
linea = linea.replace("\"", "");
|
||||
linea = linea.replace(" ", "");
|
||||
datos = linea.split(",");
|
||||
Pais p = new Pais(Integer.parseInt(datos[1]), datos[2], datos[3], datos[0], listaCon);
|
||||
listaPais.add(p);
|
||||
}
|
||||
}
|
||||
//System.out.println(GestorMapaMundi.obtenerPaisId(105, listaPais));
|
||||
for (Pais p : GestorMapaMundi.obtenerListaPaisPorContinente("04", listaPais)) {
|
||||
System.out.println(p);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.palomafp.dam2.aadd.tma.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Continente {
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
|
||||
public Continente(String cod, String nombre) {
|
||||
this.setCodigo(cod);
|
||||
this.setNombre(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() {
|
||||
String imprimir = "Continente [codigo="+this.codigo+", nombre="+this.nombre+"]";
|
||||
return imprimir;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.palomafp.dam2.aadd.tma.model;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.palomafp.dam2.aadd.tma.*;
|
||||
public class Pais {
|
||||
private int identificador;
|
||||
private String nombre;
|
||||
private String capital;
|
||||
private Continente continente;
|
||||
|
||||
public Pais() {
|
||||
this.identificador = 0;
|
||||
this.nombre = null;
|
||||
this.capital = null;
|
||||
this.continente = null;
|
||||
}
|
||||
|
||||
public Pais(int int1, String string, String string2, String string3, ArrayList<Continente> lista) {
|
||||
this.setIdentificador(int1);
|
||||
this.setNombre(string);
|
||||
this.setCapital(string2);
|
||||
this.continente = GestorMapaMundi.obtenerConPorCod(string3, lista);
|
||||
}
|
||||
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() {
|
||||
String imprimir = "Pais [identificador="+this.identificador+", nombre="+this.nombre+", capital="+this.capital+", continente="+this.continente.toString()+"]";
|
||||
|
||||
return imprimir;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user