Created
March 27, 2017 17:45
-
-
Save JDRamosC/6ad15ebaa8b4ffabd1e46d2e679f92be to your computer and use it in GitHub Desktop.
Juan Daniel Ramos Catari - Practica 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bo.edo.ubi; | |
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Paciente p1 = new Paciente("Juan", "Hombre", 15); | |
Paciente p2 = new Paciente("Maria", "Mujer", 17); | |
Paciente p3 = new Paciente("Pablo", "Hombre", 11); | |
Paciente p4 = new Paciente("Junior", "Hombre", 4); | |
Paciente p5 = new Paciente("Pepe", "Hombre", 17); | |
Paciente p6 = new Paciente("Julia", "Mujer", 16); | |
Paciente p7 = new Paciente("Erica", "Mujer", 4); | |
Paciente p8 = new Paciente("Felix", "Hombre", 42); | |
Paciente p9 = new Paciente("Ramiro", "Hombre", 23); | |
Paciente p0 = new Paciente("Yhilda", "Mujer", 13); | |
Queue<Paciente> colaPacientes = new LinkedList<Paciente>(); | |
colaPacientes.add(p1); | |
colaPacientes.add(p2); | |
colaPacientes.add(p3); | |
colaPacientes.add(p4); | |
colaPacientes.add(p5); | |
colaPacientes.add(p6); | |
colaPacientes.add(p7); | |
colaPacientes.add(p8); | |
colaPacientes.add(p9); | |
colaPacientes.add(p0); | |
//Despachar a pacientes | |
despacharMenoresdeEdad(colaPacientes); | |
//Trasladar a todos los hombres a otra cola | |
Queue<Paciente> colaHombres = new LinkedList<Paciente>(); | |
pilaSoloParaHombre(colaPacientes, colaHombres); | |
System.out.println("--------------------------------Cola Mujeres"); | |
mostrar(colaPacientes); | |
System.out.println("--------------------------------Cola Hombres"); | |
mostrar(colaHombres); | |
//Por orden de edad | |
System.out.println("--------------------------------Orden Por Edades"); | |
System.out.println("--------------------------------CoLA Mujeres"); | |
mostrarPorOrdendeEdad(colaPacientes); | |
System.out.println("--------------------------------Cola Hombres"); | |
mostrarPorOrdendeEdad(colaHombres); | |
} | |
private static void mostrarPorOrdendeEdad(Queue<Paciente> a) { | |
int n = a.size(); | |
Paciente[]arrayAux = new Paciente[n]; | |
for (int i = 0; i < n; i++) { | |
Paciente x = a.remove(); | |
arrayAux[i] = x; | |
a.add(x); | |
} | |
//Implemente la clase Comparable<> para hacer uso del metodo sort que ordena un array | |
Arrays.sort(arrayAux); | |
//Mostrar array de Pacientes :( ¿Porque sale esas cosas y no mi array? | |
for (int i = 0; i < arrayAux.length; i++) { | |
System.out.println((i+1) + ". " + arrayAux[i]); | |
} | |
} | |
private static void mostrar(Queue<Paciente> a) { | |
int n = a.size(); | |
for (int i = 0; i < n; i++) { | |
Paciente x = a.remove(); | |
System.out.println(x.getNombre() + " " + x.getSexo() + " " + x.getEdad()); | |
a.add(x); | |
} | |
} | |
private static void pilaSoloParaHombre(Queue<Paciente> colaPacientes, Queue<Paciente> colaHombres) { | |
int n = colaPacientes.size(); | |
for (int i = 0; i < n; i++) { | |
Paciente x = colaPacientes.remove(); | |
if (x.getSexo().equals("Hombre")) { | |
colaHombres.add(x); | |
} else { | |
colaPacientes.add(x); | |
} | |
} | |
} | |
private static void despacharMenoresdeEdad(Queue<Paciente> a) { | |
int n = a.size(); | |
System.out.println("-------------------------Lista de pacientes sin menores de 10 años."); | |
for (int i = 0; i < n; i++) { | |
Paciente x = a.remove(); | |
if (x.getEdad() > 10) { | |
System.out.println(x.getNombre() + " " + x.getSexo() + " " + x.getEdad()); | |
a.add(x); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bo.edo.ubi; | |
import java.util.Comparator; | |
/** | |
* Created by HP-PC on 23/03/2017. | |
*/ | |
public class Paciente implements Comparable<Paciente>{ | |
private String nombre; | |
private String sexo; | |
private int edad; | |
public Paciente(String nombre, String sexo, int edad) { | |
this.nombre = nombre; | |
this.sexo = sexo; | |
this.edad = edad; | |
} | |
public Paciente() { | |
this.nombre = ""; | |
this.sexo = ""; | |
this.edad = 0; | |
} | |
public String getNombre() { | |
return nombre; | |
} | |
public void setNombre(String nombre) { | |
this.nombre = nombre; | |
} | |
public String getSexo() { | |
return sexo; | |
} | |
public void setSexo(String sexo) { | |
this.sexo = sexo; | |
} | |
public int getEdad() { | |
return edad; | |
} | |
public void setEdad(int edad) { | |
this.edad = edad; | |
} | |
@Override | |
public int compareTo(Paciente o) { | |
if (edad < o.edad){ | |
return -1; | |
} | |
if(edad > o.edad){ | |
return 1; | |
} | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
esta mal