Está en la página 1de 3

package Colas_A;

import javax.swing.JOptionPane;
public class Colas_A {
/*
* Autor N1b3r
*/
private static Colas ColaNueva = new Colas();
public static void main(String[] args) {
while (true) {
switch (Byte.parseByte(JOptionPane.showInputDialog(null,
"1 - Tamaño de la cola!\n"
+ "2 - Ingresar valor!\n"
+ "3 - Borrar valor!\n"
+ "4 - Mostrar valores!\n"
+ "5 - Salir!", "Made by N1b3r", 3))) {
case 1:
ColaNueva.tamaño();
break;
case 2:
ColaNueva.ingresar();
break;
case 3:
ColaNueva.borrar();
break;
case 4:
ColaNueva.mostrar();
break;
case 5:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "Instrucciòn no valida!\nI
ntente de nuevo!", "Made by N1b3r", 0);
break;
}
}
}
}
class Colas {
private static boolean ok = false;
private static byte ingreso = -1, frente = 0, tam;
private static String[] arreglo;
private static String OUT = "";
static void tamaño() {
if (ok == false) {
tam = Byte.parseByte(JOptionPane.showInputDialog(null, "Diga el tamaño
de la cola", "Tamaño", 3));
if (tam > 0) {
arreglo = new String[tam];
ingreso++;
ok = true;
} else {
JOptionPane.showMessageDialog(null, "Instrucciòn no valida!\nInten
te de nuevo!", "Made by N1b3r", 0);
}
} else {
JOptionPane.showMessageDialog(null, "La cola es de tamaño " + arreglo.
length + "!", "Tamaño", 1);
}
}
static void ingresar() {
if (ingreso >= 0) {
if (ingreso != arreglo.length) {
arreglo[ingreso] = JOptionPane.showInputDialog(null, "Ingrese el
valor " + (ingreso + 1), "Ingreso", 3);
ingreso++;
} else {
JOptionPane.showMessageDialog(null, "La cola esta llena!", "Ingr
eso", 0);
}
} else {
JOptionPane.showMessageDialog(null, "No ha establecido el tamaño de la
cola!", "Ingreso", 2);
}
}
static void borrar() {
if (ingreso >= 0) {
if (arreglo[frente] == null) {
JOptionPane.showMessageDialog(null, "La cola está totalmente vacia
!", "Borrar", 2);
} else {
JOptionPane.showMessageDialog(null, "El valor " + arreglo[frente
] + " fue borrado", "Borrar", 1);
arreglo[frente] = null;
for (byte i = frente; i < arreglo.length - 1; i++) {
arreglo[i] = arreglo[i + 1];
arreglo[i + 1] = null;
}
ingreso--;
}
} else {
JOptionPane.showMessageDialog(null, "No ha establecido el tamaño de la
cola!", "Borrar", 2);
}
}
static void mostrar() {
if (ingreso >= 0) {
OUT = "";
if (arreglo[frente] != null) {
for (byte j = frente; j < arreglo.length; j++) {
if (arreglo[j] != null) {
OUT += " " + arreglo[j];
} else {
OUT += " vacío";
}
}
JOptionPane.showMessageDialog(null, OUT, "Mostrar", 1);
} else {
JOptionPane.showMessageDialog(null, "La cola está totalmente vacia
!", "Mostrar", 2);
}
} else {
JOptionPane.showMessageDialog(null, "No ha establecido el tamaño de la
cola!", "Mostrar", 2);
}
}
}
// Made by N1b3r

También podría gustarte