Advertisement
santiagol26

reclamosUnal

Oct 22nd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.06 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Parcial {
  5.    
  6.   static class Lista<T> {
  7.    
  8.     static class NodoLista<T> {
  9.       NodoLista<T> anterior;
  10.       NodoLista<T> siguiente;
  11.       int cedula;
  12.       String texto;
  13.       double promedio;
  14.       public NodoLista(double promedio,int cedula,String texto) {
  15.         this.promedio=promedio;
  16.         this.cedula = cedula;
  17.         this.texto = texto;
  18.         siguiente = anterior = null;
  19.       }
  20.     }
  21.    
  22.     NodoLista<T> frente;
  23.     NodoLista<T> cola;
  24.     int longitud;
  25.  
  26.     public Lista() {
  27.       frente = cola = null;
  28.       longitud = 0;
  29.     }
  30.     public void insertarFrente(double promedio,int cedula,String texto) {
  31.       NodoLista<T> nodo = new NodoLista<>(promedio,cedula,texto);
  32.       if (longitud == 0) {
  33.         cola = nodo;
  34.       } else {
  35.         frente.anterior = nodo;
  36.         nodo.siguiente = frente;
  37.       }
  38.       frente = nodo;
  39.       longitud++;
  40.     }
  41.     public void insertarCola(double promedio,int cedula,String texto) {
  42.  
  43.       if (longitud == 0) {
  44.         insertarFrente(promedio,cedula,texto);
  45.       } else {
  46.          NodoLista<T> nodo = new NodoLista<>(promedio,cedula,texto);
  47.          cola.siguiente = nodo;
  48.          nodo.anterior = cola;
  49.          cola = nodo;
  50.          longitud++;
  51.       }
  52.     }
  53.    
  54.     public String removerFrente() {
  55.       if (longitud == 0) {
  56.         return null;
  57.       }
  58.       String texto= frente.texto;
  59.       frente = frente.siguiente;
  60.       longitud--;
  61.  
  62.       if (longitud > 0) {
  63.         frente.anterior = null;
  64.       }
  65.       return texto;
  66.     }
  67.    
  68.     public String removerCola() {
  69.        if (longitud == 0) {
  70.         return null;
  71.        }
  72.       String texto=cola.texto;
  73.       cola = cola.anterior;
  74.       longitud--;
  75.       if (longitud > 0) {
  76.         cola.siguiente = null;
  77.       }
  78.       return texto;
  79.     }
  80.  
  81.     public String remover(int posicion) { //remover metodo del texto
  82.       if (posicion == 0) {
  83.         return removerFrente();
  84.       }
  85.       if (posicion == longitud-1) {
  86.         return removerCola();
  87.       }
  88.       NodoLista<T> ref = frente;
  89.  
  90.       for (int i = 0; i < posicion; i++) {
  91.         ref = ref.siguiente;
  92.       }
  93.       String texto = ref.texto;
  94.       ref.anterior.siguiente = ref.siguiente;
  95.       ref.siguiente.anterior = ref.anterior;
  96.       longitud--;
  97.       return texto;
  98.     }
  99.    
  100.     public double valorEn(int posicion){        //valor en la posicion metodo
  101.       NodoLista<T> ref = frente;
  102.       for (int i = 0; i < posicion; i++, ref = ref.siguiente);
  103.       return ref.promedio;
  104.     }
  105.     public int cedulaEn( Integer posicion){        //valor en la posicion metodo
  106.         NodoLista<T> ref = frente;
  107.         for (int i = 0; i < posicion; i++, ref = ref.siguiente);
  108.         return ref.cedula;
  109.       }
  110.   }  
  111.  
  112.   public static void main(String[] args) throws IOException {
  113.      
  114.     Lista<Object> lista = new Lista<>();
  115.     Scanner teclado= new Scanner(System.in);
  116.     //System.out.println("digite el numero de casos ");
  117.     int casos= teclado.nextInt();
  118.      while(casos!=0){
  119.          casos--;
  120.           //System.out.println("escriba reclamo o atender");
  121.           String queja=teclado.next();
  122.          if (queja.equals("atender")){
  123.              if (lista.longitud>0){
  124.                  double mayor=0;
  125.                  int posR=0;
  126.                  for ( int n=0;n<lista.longitud;n++){
  127.                      if(lista.valorEn(n)>= mayor){
  128.                          mayor=lista.valorEn(n);
  129.                          posR=n;
  130.                         }            
  131.                  }
  132.                  System.out.println(lista.cedulaEn(posR)+" "+lista.remover(posR));
  133.                  
  134.              }
  135.              else {
  136.                  System.out.println("No hay reclamos pendientes");
  137.                  continue;
  138.              }
  139.          }       
  140.          else if (queja.equals("reclamo")) {
  141.               //System.out.println("digite su numero de cedula ");       
  142.               int cedula=teclado.nextInt();
  143.               //System.out.println("que reclamo tiene? ");
  144.               teclado.nextLine();
  145.               String texto = teclado.nextLine();
  146.               //System.out.println("digite su PAPA ");
  147.               double promedio=teclado.nextDouble();
  148.               lista.insertarFrente(promedio, cedula, texto);
  149.          }
  150.           else{continue;}
  151.       }  
  152.    teclado.close();  
  153.   }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement