ejercicio3
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-23">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Ficheros_03</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>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=23
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=23
|
||||
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.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=23
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,108 @@
|
||||
package org.palomafp.dam2.aadd.rces;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.palomafp.dam2.aadd.rces.model.Continente;
|
||||
import org.palomafp.dam2.aadd.rces.model.Pais;
|
||||
|
||||
public class AppPrincipal {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\ricardo\\aadd\\fic03\\informacion_paises.txt"));
|
||||
ArrayList<Continente> continentes = new ArrayList<>();
|
||||
ArrayList<Pais> paises = new ArrayList<>();
|
||||
String linea;
|
||||
while((linea = br.readLine()) != null) {
|
||||
if(!linea.startsWith("#") && !linea.startsWith("--")) {
|
||||
String infoDatos[] = linea.replace("\"", "\'").split(",");
|
||||
|
||||
String codigoContinente = infoDatos[0];
|
||||
int identificadorPais = Integer.parseInt(infoDatos[1]);
|
||||
String nombrePais = infoDatos[2];
|
||||
String nombreCapital = infoDatos[3];
|
||||
Continente continente = new Continente(codigoContinente, null);
|
||||
|
||||
continentes.add(continente);
|
||||
paises.add(new Pais(identificadorPais,nombrePais,nombreCapital,continente));
|
||||
}
|
||||
|
||||
}
|
||||
int menu;
|
||||
do {
|
||||
System.out.println("1. Pulsa 1 para buscar pais por el identificador \n2. Pulsa 2 para enseñar los paises que tiene el continente con el codigo");
|
||||
System.out.println("escriba -1 si quiere salir de la app");
|
||||
menu = sc.nextInt();
|
||||
|
||||
switch(menu) {
|
||||
case 1 :
|
||||
System.out.println("escriba el identificador ");
|
||||
int identificador = sc.nextInt();
|
||||
obtenerPais(identificador,paises);
|
||||
break;
|
||||
case 2:
|
||||
sc.nextLine();
|
||||
System.out.println("escriba el codigo del continente");
|
||||
|
||||
String codigo = sc.nextLine();
|
||||
|
||||
ArrayList<Pais>paisesContinente = new ArrayList<>();
|
||||
paisesContinente = obtenerPaisesContinente(codigo,paises);
|
||||
System.out.println("el continente con el codigo "+codigo+" tiene estos paises");
|
||||
for(int i = 0; i < paisesContinente.size();i++){
|
||||
System.out.println(paisesContinente.get(i).toString());
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
System.out.println("saliendo...");
|
||||
break;
|
||||
default:
|
||||
System.out.println("te has equivocado");
|
||||
}
|
||||
|
||||
}while(menu != -1);
|
||||
|
||||
}catch( Exception e) {
|
||||
System.out.println("error");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void obtenerPais(int identificador,ArrayList<Pais>paises) {
|
||||
|
||||
for(int i = 0; i < paises.size(); i++) {
|
||||
|
||||
if(paises.get(i).getIdentificador() == (identificador)) {
|
||||
|
||||
System.out.println(paises.get(i).toString());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<Pais> obtenerPaisesContinente(String codigo ,ArrayList<Pais> paises){
|
||||
|
||||
|
||||
ArrayList<Pais> paisesContinente = new ArrayList<>();
|
||||
for(int i = 0; i < paises.size(); i++) {
|
||||
if(paises.get(i).getContinente().getCodigo().replace("\'", "").equals(codigo)) {
|
||||
paisesContinente.add(paises.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return paisesContinente;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.palomafp.dam2.aadd.rces.model;
|
||||
|
||||
public class Continente {
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
public Continente(String codigo, String nombre) {
|
||||
super();
|
||||
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 + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.palomafp.dam2.aadd.rces.model;
|
||||
|
||||
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) {
|
||||
super();
|
||||
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 + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user