Advertisement
robeeeert

archivo colas

Jun 16th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.57 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.LinkedList;
  3. import java.util.Queue;
  4. public class ArchivoColas {
  5.     Queue<Cita> colaOdonto = new LinkedList<>();
  6.     Queue<Cita> colaGastro = new LinkedList<>();
  7.     Queue<Cita> colaDerma = new LinkedList<>();
  8.     Queue<Cita> colaNeuro = new LinkedList<>();
  9.     public void ingresarCita(Cita citas){
  10.         try{
  11.             File f = new File("Citas_10062023.txt");
  12.             FileWriter fw;
  13.             BufferedWriter bw;
  14.             if (f.exists() & (f.length() !=0)){
  15.                 fw = new FileWriter(f,true);
  16.                 bw = new BufferedWriter(fw);
  17.                 bw.newLine();  
  18.             }else{
  19.                 fw = new FileWriter(f);
  20.                 bw = new BufferedWriter(fw);  
  21.         }
  22.         bw.write(citas.getCui());
  23.         bw.write("%");
  24.         bw.write(citas.getNombres());
  25.         bw.write("%");
  26.         bw.write(citas.getApellidos());
  27.         bw.write("%");
  28.         bw.write(citas.getFechaNacimiento());
  29.         bw.write("%");
  30.         bw.write(citas.getGenero());
  31.         bw.write("%");
  32.         bw.write(citas.getEspecialidad());
  33.         bw.close();
  34.         fw.close();
  35.         }catch(Exception e){
  36.             System.out.println("Error de E/S " + e);
  37.         }
  38.        
  39.     }
  40.    
  41.     public void cargarCitas(){
  42.         /*try{
  43.             File f = new File ("Citas_10062023.txt");
  44.             if (f.exists()){
  45.                     FileReader fr = new FileReader(f);
  46.                     BufferedReader br = new BufferedReader(fr);
  47.                     String linea;
  48.                     while((linea = br.readLine()) !=null){
  49.                         String[] arreglo = linea.split("%");
  50.                         if (arreglo[5].equals("1") || arreglo[5].equals("2") || arreglo[5].equals("3") || arreglo[5].equals("4")){
  51.                         Cita citas = new Cita(arreglo[0], arreglo[1], arreglo[2], arreglo[3],arreglo[4],arreglo[5]);
  52.                         System.out.println(citas.toString());
  53.                         }//ifarreglo
  54.                     }//while
  55.                     br.close();
  56.                     fr.close();
  57.                 }//if
  58.             }catch(Exception e){
  59.                 System.out.println("Error de S/E" + e);
  60.             }//TryCatch
  61.  
  62.         */  
  63.         try{
  64.             File f = new File ("Citas_10062023.txt");
  65.             if (f.exists()){
  66.                     FileReader fr = new FileReader(f);
  67.                     BufferedReader br = new BufferedReader(fr);
  68.                     String linea;
  69.                     while((linea = br.readLine()) !=null){
  70.                         String[] arreglo = linea.split("%");
  71.                         Cita cita = new Cita(arreglo[0], arreglo[1], arreglo[2], arreglo[3],arreglo[4],arreglo[5]);
  72.                         switch(cita.getEspecialidad()){
  73.                             case "1":
  74.                                 colaOdonto.add(cita);
  75.                                 break;
  76.                             case "2":
  77.                                 colaGastro.add(cita);
  78.                                 break;
  79.                             case "3":
  80.                                 colaDerma.add(cita);
  81.                                 break;
  82.                             case "4":
  83.                                 colaNeuro.add(cita);
  84.                                 break;
  85.                         }
  86.                     }//while
  87.                     br.close();
  88.                     fr.close();
  89.             }//if
  90.         }catch(Exception e){
  91.                 System.out.println("Error de S/E" + e);
  92.         }//TryCatch
  93.     }
  94.     public void mostrarCitas(){
  95.         while(!colaOdonto.isEmpty()){
  96.             System.out.println("\tCitas Odontologia En cola:\n"+ colaOdonto+"\n");
  97.             break;
  98.         }
  99.         while(!colaGastro.isEmpty()){
  100.             System.out.println("\tCitas Gastroenterologia En cola:\n"+ colaGastro+"\n");
  101.             break;
  102.         }
  103.         while(!colaDerma.isEmpty()){
  104.             System.out.println("\tCitas Dermatologia En cola:\n"+ colaDerma+"\n");
  105.             break;
  106.         }
  107.         while(!colaNeuro.isEmpty()){
  108.             System.out.println("\tCitas Neurologia En cola:\n"+ colaNeuro+"\n");
  109.             break;
  110.         }
  111.     }
  112.     public void atenderOdonto(){
  113.         if(!colaOdonto.isEmpty()) {
  114.             Cita cita = colaOdonto.peek();
  115.             System.out.println("Atendiendo Al Paciente En Odontología: " + cita.toString());
  116.             colaOdonto.poll();
  117.         }else{
  118.         System.out.println("No Hay Pacientes En Cola De Odontología.");
  119.         }
  120.     }
  121.     public  void atenderGastro(){
  122.         if(!colaGastro.isEmpty()) {
  123.             Cita cita = colaGastro.peek();
  124.             System.out.println("Atendiendo Al Paciente En Odontología: " + cita.toString());
  125.             colaGastro.poll();
  126.         }else{
  127.         System.out.println("No Hay Pacientes Cola De Gastroenterologia.");
  128.         }
  129.     }
  130.     public void atenderDerma(){
  131.         if(!colaDerma.isEmpty()) {
  132.             Cita cita = colaDerma.peek();
  133.             System.out.println("Atendiendo Al Paciente En Dermatologia: " + cita.toString());
  134.             colaDerma.poll();
  135.         }else{
  136.         System.out.println("No Hay Pacientes En Cola De Dermatologia.");
  137.         }
  138.     }
  139.      public void atenderNeuro(){
  140.         if(!colaNeuro.isEmpty()) {
  141.             Cita cita = colaNeuro.peek();
  142.             System.out.println("Atendiendo Al Paciente En Neurologia: " + cita.toString());
  143.             colaNeuro.poll();
  144.         }else{
  145.         System.out.println("No Hay Pacientes En Cola De Neurologia.");
  146.         }
  147.     }
  148. }
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement