/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.util.LinkedList;
import java.util.Random;
public class PacientesApp{
public static void main(String[] args){
Random rand = new Random();
MiCola<Paciente> p1s = new MiCola<>();
MiCola<Paciente> pAs = new MiCola<>();
MiCola<Paciente> pBs = new MiCola<>();
int i=1, t1=0;
t1 += (rand.nextInt(3)+1);
while(t1<=210){
Paciente p = new Paciente(i,t1);
p1s.push(p);
t1 += (rand.nextInt(3)+1);
i++;
}
Enfermera enfermera = new Enfermera();
enfermera.triaje(p1s, pAs, pBs);
Medico medico = new Medico();
medico.curar(p1s, pAs, pBs);
System.out.println("Atención de pacientes por los médicos A y B");
System.out.println("Número\tMédico\tt.Espera\tt.Atendido");
for(int k = p1s.size()-1; k!=0;k--){
System.out.println(p1s.get(k).Cadena());
}
}
}
class MiCola<E>{
LinkedList<E> list;
public MiCola(){
list = new LinkedList<E>();
}
public void push(E item){
list.addFirst(item);
}
public E pull(){
return list.removeFirst();
}
public int size(){
return list.size();
}
public E get(int i){
return list.get(i);
}
}
class Enfermera{
void triaje(MiCola<Paciente> p1s, MiCola<Paciente> pAs, MiCola<Paciente> pBs){
Random rand = new Random();
int r = 0;
int t = p1s.size();
int p = 60;
for(int i = 0; i<t; i++){
r = rand.nextInt(2)+1;
p1s.get(i).t2 = p;
p1s.get(i).t3 = p + r;
if(r==1){
pAs.push(p1s.get(i));
}else{
pBs.push(p1s.get(i));
}
p=p1s.get(i).t3;
}
while(t!=0){
p1s.pull();
t--;
}
}
}
class Paciente{
public int numero, t1,t2,t3,t4,t5;
public char medico;
Paciente(int numero, int t1){
this.numero = numero;
this.t1 = t1;
}
public String Cadena(){
return numero + "\t"+ medico + "\t" + (t2-t1+t4-t3) + "\t\t" +(t3-t2+t5-t4);
}
}
class Medico{
void curar(MiCola<Paciente> p1s, MiCola<Paciente> pAs, MiCola<Paciente> pBs){
Random rand = new Random();
int r = 0;
int t = pAs.size();
int p = 60;
for(int i = 0; i<t;i++){
r = rand.nextInt(10)+1;
pAs.get(i).t4 = p;
pAs.get(i).t5 = p+r;
pAs.get(i).medico = 'A';
p=pAs.get(i).t5;
}
while(t!=0){
p1s.push(pAs.pull());
t--;
}
t = pBs.size();
p = 60;
for(int i = 0; i<t;i++){
r = rand.nextInt(10)+1;
pBs.get(i).t4 = p;
pBs.get(i).t5 = p+r;
pBs.get(i).medico = 'B';
p = pBs.get(i).t5;
}
while(t!=0){
p1s.push(pBs.pull());
t--;
}
}
}