Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. /**
  2.      * Introduce en la cola el parametro pNum.
  3.      * @param pNum es el numero que se introduce en la cola.
  4.      * @return devuelve true si se ha podido introducir correctamente
  5.      * @throws IllegalStateException si el numero a introducir no corresponde en signo
  6.      * al anterior, salta esta excepcion.
  7.      */
  8.     public boolean add(int pNum) throws Exception {
  9.         if (!isEmpty()) {
  10.             if ((lista.get(lista.size() - 1) < 0 && pNum > 0) || (lista.get(lista.size() - 1) > 0 && pNum < 0)) {
  11.                 lista.add(pNum);
  12.                 return true;
  13.             } else if (lista.get(lista.size() - 1) == pNum) {
  14.                 return true;
  15.             } else {
  16.                 throw new IllegalStateException();
  17.             }
  18.         } else {
  19.             lista.add(pNum);
  20.         }
  21.         return true;
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement