Advertisement
robeeeert

archivo pilas

Jun 16th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.72 KB | None | 0 0
  1. package com.mycompany.principalpilas;
  2.  
  3. /**
  4.  *
  5.  * @author ianto
  6.  */
  7. import java.util.Stack;
  8. import java.io.*;
  9. public class ArchivoPilas {
  10.     Stack<Clientes> pilaVentas = new Stack<>();
  11.     Stack<Clientes> pilaCompras = new Stack<>();
  12.     Stack<Clientes> pilaConta = new Stack<>();
  13.     Stack<Clientes> pilaSiste = new Stack<>();
  14.     public void ingresarCliente(Clientes cliente){
  15.         try{
  16.             File f = new File("Clientes_10062023.txt");
  17.             FileWriter fw;
  18.             BufferedWriter bw;
  19.             if (f.exists() & (f.length() !=0)){
  20.                 fw = new FileWriter(f,true);
  21.                 bw = new BufferedWriter(fw);
  22.                 bw.newLine();  
  23.             }else{
  24.                 fw = new FileWriter(f);
  25.                 bw = new BufferedWriter(fw);  
  26.             }
  27.             bw.write(cliente.getNit());
  28.             bw.write("%");
  29.             bw.write(cliente.getNombres());
  30.             bw.write("%");
  31.             bw.write(cliente.getApellidos());
  32.             bw.write("%");
  33.             bw.write(cliente.getFechaNacimiento());
  34.             bw.write("%");
  35.             bw.write(cliente.getGenero());
  36.             bw.write("%");
  37.             bw.write(cliente.getDepartamento());
  38.             bw.close();
  39.             fw.close();
  40.         }catch(Exception e){
  41.             System.out.println("Error de E/S " + e);
  42.         }
  43.     }
  44.     public void cargarClientes(){
  45.         try{
  46.             File f = new File ("Clientes_10062023.txt");
  47.             if (f.exists()){
  48.                     FileReader fr = new FileReader(f);
  49.                     BufferedReader br = new BufferedReader(fr);
  50.                     String linea;
  51.                     while((linea = br.readLine()) !=null){
  52.                         String[] arreglo = linea.split("%");
  53.                         Clientes cliente = new Clientes(arreglo[0], arreglo[1], arreglo[2], arreglo[3],arreglo[4],arreglo[5]);
  54.                         switch(cliente.getDepartamento()){
  55.                             case "1":
  56.                                 pilaVentas.push(cliente);
  57.                                 break;
  58.                             case "2":
  59.                                 pilaCompras.push(cliente);
  60.                                 break;
  61.                             case "3":
  62.                                 pilaConta.push(cliente);
  63.                                 break;
  64.                             case "4":
  65.                                 pilaSiste.push(cliente);
  66.                                 break;
  67.                         }
  68.                     }//while
  69.                     br.close();
  70.                     fr.close();
  71.             }//if
  72.         }catch(Exception e){
  73.                 System.out.println("Error de S/E" + e);
  74.         }//TryCatch
  75.     }
  76.     public void mostrarClientes(){
  77.         while(!pilaVentas.empty()){
  78.             System.out.println("\tClientes Ventas En Pila:\n"+ pilaVentas+"\n");
  79.             break;
  80.         }
  81.         while(!pilaCompras.empty()){
  82.             System.out.println("\tClientes Compras En Pila:\n"+ pilaCompras+"\n");
  83.             break;
  84.         }
  85.         while(!pilaConta.empty()){
  86.             System.out.println("\tClientes Conta En Pila:\n"+ pilaConta+"\n");
  87.             break;
  88.         }
  89.         while(!pilaSiste.empty()){
  90.             System.out.println("\tCliente Sistemas En Pila:\n"+ pilaSiste+"\n");
  91.             break;
  92.         }
  93.     }
  94.     public void atenderVentas(){
  95.         if(!pilaVentas.empty()) {
  96.             Clientes cliente = pilaVentas.peek();
  97.             System.out.println("Atendiendo Al Cliente En Ventas: " + cliente.toString());
  98.             pilaVentas.pop();
  99.         }else{
  100.         System.out.println("No Hay Clientes En La Pila Ventas.");
  101.         }
  102.     }
  103.     public void atenderCompras(){
  104.         if(!pilaCompras.empty()) {
  105.             Clientes cliente = pilaCompras.peek();
  106.             System.out.println("Atendiendo Al Cliente En Compras: " + cliente.toString());
  107.             pilaCompras.pop();
  108.         }else{
  109.         System.out.println("No Hay Clientes En La Pila Compras.");
  110.         }
  111.     }
  112.     public void atenderConta(){
  113.         if(!pilaConta.empty()) {
  114.             Clientes cliente = pilaConta.peek();
  115.             System.out.println("Atendiendo Al Cliente En Contabilidad: " + cliente.toString());
  116.             pilaConta.pop();
  117.         }else{
  118.         System.out.println("No Hay Clientes En La Pila Contabilidad.");
  119.         }
  120.     }
  121.     public void atenderSiste(){
  122.         if(!pilaSiste.empty()) {
  123.             Clientes cliente = pilaSiste.peek();
  124.             System.out.println("Atendiendo Al Cliente En Sistemas: " + cliente.toString());
  125.             pilaSiste.pop();
  126.         }else{
  127.         System.out.println("No Hay Clientes En La Pila Sistemas.");
  128.         }
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement