Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.LinkedList;
- import java.util.Queue;
- public class ArchivoColas {
- Queue<Cita> colaOdonto = new LinkedList<>();
- Queue<Cita> colaGastro = new LinkedList<>();
- Queue<Cita> colaDerma = new LinkedList<>();
- Queue<Cita> colaNeuro = new LinkedList<>();
- public void ingresarCita(Cita citas){
- try{
- File f = new File("Citas_10062023.txt");
- FileWriter fw;
- BufferedWriter bw;
- if (f.exists() & (f.length() !=0)){
- fw = new FileWriter(f,true);
- bw = new BufferedWriter(fw);
- bw.newLine();
- }else{
- fw = new FileWriter(f);
- bw = new BufferedWriter(fw);
- }
- bw.write(citas.getCui());
- bw.write("%");
- bw.write(citas.getNombres());
- bw.write("%");
- bw.write(citas.getApellidos());
- bw.write("%");
- bw.write(citas.getFechaNacimiento());
- bw.write("%");
- bw.write(citas.getGenero());
- bw.write("%");
- bw.write(citas.getEspecialidad());
- bw.close();
- fw.close();
- }catch(Exception e){
- System.out.println("Error de E/S " + e);
- }
- }
- public void cargarCitas(){
- /*try{
- File f = new File ("Citas_10062023.txt");
- if (f.exists()){
- FileReader fr = new FileReader(f);
- BufferedReader br = new BufferedReader(fr);
- String linea;
- while((linea = br.readLine()) !=null){
- String[] arreglo = linea.split("%");
- if (arreglo[5].equals("1") || arreglo[5].equals("2") || arreglo[5].equals("3") || arreglo[5].equals("4")){
- Cita citas = new Cita(arreglo[0], arreglo[1], arreglo[2], arreglo[3],arreglo[4],arreglo[5]);
- System.out.println(citas.toString());
- }//ifarreglo
- }//while
- br.close();
- fr.close();
- }//if
- }catch(Exception e){
- System.out.println("Error de S/E" + e);
- }//TryCatch
- */
- try{
- File f = new File ("Citas_10062023.txt");
- if (f.exists()){
- FileReader fr = new FileReader(f);
- BufferedReader br = new BufferedReader(fr);
- String linea;
- while((linea = br.readLine()) !=null){
- String[] arreglo = linea.split("%");
- Cita cita = new Cita(arreglo[0], arreglo[1], arreglo[2], arreglo[3],arreglo[4],arreglo[5]);
- switch(cita.getEspecialidad()){
- case "1":
- colaOdonto.add(cita);
- break;
- case "2":
- colaGastro.add(cita);
- break;
- case "3":
- colaDerma.add(cita);
- break;
- case "4":
- colaNeuro.add(cita);
- break;
- }
- }//while
- br.close();
- fr.close();
- }//if
- }catch(Exception e){
- System.out.println("Error de S/E" + e);
- }//TryCatch
- }
- public void mostrarCitas(){
- while(!colaOdonto.isEmpty()){
- System.out.println("\tCitas Odontologia En cola:\n"+ colaOdonto+"\n");
- break;
- }
- while(!colaGastro.isEmpty()){
- System.out.println("\tCitas Gastroenterologia En cola:\n"+ colaGastro+"\n");
- break;
- }
- while(!colaDerma.isEmpty()){
- System.out.println("\tCitas Dermatologia En cola:\n"+ colaDerma+"\n");
- break;
- }
- while(!colaNeuro.isEmpty()){
- System.out.println("\tCitas Neurologia En cola:\n"+ colaNeuro+"\n");
- break;
- }
- }
- public void atenderOdonto(){
- if(!colaOdonto.isEmpty()) {
- Cita cita = colaOdonto.peek();
- System.out.println("Atendiendo Al Paciente En Odontología: " + cita.toString());
- colaOdonto.poll();
- }else{
- System.out.println("No Hay Pacientes En Cola De Odontología.");
- }
- }
- public void atenderGastro(){
- if(!colaGastro.isEmpty()) {
- Cita cita = colaGastro.peek();
- System.out.println("Atendiendo Al Paciente En Odontología: " + cita.toString());
- colaGastro.poll();
- }else{
- System.out.println("No Hay Pacientes Cola De Gastroenterologia.");
- }
- }
- public void atenderDerma(){
- if(!colaDerma.isEmpty()) {
- Cita cita = colaDerma.peek();
- System.out.println("Atendiendo Al Paciente En Dermatologia: " + cita.toString());
- colaDerma.poll();
- }else{
- System.out.println("No Hay Pacientes En Cola De Dermatologia.");
- }
- }
- public void atenderNeuro(){
- if(!colaNeuro.isEmpty()) {
- Cita cita = colaNeuro.peek();
- System.out.println("Atendiendo Al Paciente En Neurologia: " + cita.toString());
- colaNeuro.poll();
- }else{
- System.out.println("No Hay Pacientes En Cola De Neurologia.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement