Advertisement
robeeeert

archivo colas

Jun 16th, 2023
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.59 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.     public void cargarCitas(){
  40.         try{
  41.             File f = new File ("Citas_10062023.txt");
  42.             if (f.exists()){
  43.                     FileReader fr = new FileReader(f);
  44.                     BufferedReader br = new BufferedReader(fr);
  45.                     String linea;
  46.                     while((linea = br.readLine()) !=null){
  47.                         String[] arreglo = linea.split("%");
  48.                         Cita cita = new Cita(arreglo[0], arreglo[1], arreglo[2], arreglo[3],arreglo[4],arreglo[5]);
  49.                         switch(cita.getEspecialidad()){
  50.                             case "1":
  51.                                 colaOdonto.add(cita);
  52.                                 break;
  53.                             case "2":
  54.                                 colaGastro.add(cita);
  55.                                 break;
  56.                             case "3":
  57.                                 colaDerma.add(cita);
  58.                                 break;
  59.                             case "4":
  60.                                 colaNeuro.add(cita);
  61.                                 break;
  62.                         }
  63.                     }//while
  64.                     br.close();
  65.                     fr.close();
  66.             }//if
  67.         }catch(Exception e){
  68.                 System.out.println("Error de S/E" + e);
  69.         }//TryCatch
  70.     }
  71.     public void mostrarCitas(){
  72.         while(!colaOdonto.isEmpty()){
  73.             System.out.println("\tCitas Odontologia En cola:\n"+ colaOdonto+"\n");
  74.             break;
  75.         }
  76.         while(!colaGastro.isEmpty()){
  77.             System.out.println("\tCitas Gastroenterologia En cola:\n"+ colaGastro+"\n");
  78.             break;
  79.         }
  80.         while(!colaDerma.isEmpty()){
  81.             System.out.println("\tCitas Dermatologia En cola:\n"+ colaDerma+"\n");
  82.             break;
  83.         }
  84.         while(!colaNeuro.isEmpty()){
  85.             System.out.println("\tCitas Neurologia En cola:\n"+ colaNeuro+"\n");
  86.             break;
  87.         }
  88.     }
  89.     public void atenderOdonto(){
  90.         if(!colaOdonto.isEmpty()) {
  91.             Cita cita = colaOdonto.peek();
  92.             System.out.println("Atendiendo Al Paciente En Odontología: " + cita.toString());
  93.             colaOdonto.poll();
  94.         }else{
  95.         System.out.println("No Hay Pacientes En Cola De Odontología.");
  96.         }
  97.     }
  98.     public  void atenderGastro(){
  99.         if(!colaGastro.isEmpty()) {
  100.             Cita cita = colaGastro.peek();
  101.             System.out.println("Atendiendo Al Paciente En Odontología: " + cita.toString());
  102.             colaGastro.poll();
  103.         }else{
  104.         System.out.println("No Hay Pacientes Cola De Gastroenterologia.");
  105.         }
  106.     }
  107.     public void atenderDerma(){
  108.         if(!colaDerma.isEmpty()) {
  109.             Cita cita = colaDerma.peek();
  110.             System.out.println("Atendiendo Al Paciente En Dermatologia: " + cita.toString());
  111.             colaDerma.poll();
  112.         }else{
  113.         System.out.println("No Hay Pacientes En Cola De Dermatologia.");
  114.         }
  115.     }
  116.      public void atenderNeuro(){
  117.         if(!colaNeuro.isEmpty()) {
  118.             Cita cita = colaNeuro.peek();
  119.             System.out.println("Atendiendo Al Paciente En Neurologia: " + cita.toString());
  120.             colaNeuro.poll();
  121.         }else{
  122.         System.out.println("No Hay Pacientes En Cola De Neurologia.");
  123.         }
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement