Skip to content

Instantly share code, notes, and snippets.

@j2deme
Last active May 26, 2021 18:03
Show Gist options
  • Save j2deme/c3941a5e3889f19414717ea52ddb07fd to your computer and use it in GitHub Desktop.
Save j2deme/c3941a5e3889f19414717ea52ddb07fd to your computer and use it in GitHub Desktop.
Taquilla de Cine con Matriz Tridimensional
package com.j2deme;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
int opcion,sala,fila,butaca;
boolean[][][] cine = new boolean[3][10][10];
//Inicializar
for (int i=0; i < 3; i++){
for(int j=0; j < 10; j++){
for(int k=0; k < 10; k++){
cine[i][j][k] = false;
}
}
}
// Cambiar el valor de una coordenada
do {
System.out.print("Sala [1-3]: ");
sala = teclado.nextInt();
System.out.print("Fila [1-10]: ");
fila = teclado.nextInt();
System.out.print("Butaca [1-10]: ");
butaca = teclado.nextInt();
// Verificar que la coordenada este libre (sea false)
if (!cine[sala - 1][fila - 1][butaca - 1]){
cine[sala - 1][fila - 1][butaca - 1] = true;
} else {
System.out.println("Asiento ocupado");
}
System.out.print("Desea comprar otro asiento? [1-Sí / 0-No]");
opcion = teclado.nextInt();
} while (opcion != 0);
// Impresión de la matriz 3D
/*for (int i=0; i < 3; i++){
System.out.printf("= Sala %d =\n", i+1);
for(int j=0; j < 10; j++){
for(int k=0; k < 10; k++){
System.out.printf("Fila %d / Butaca %d:", j+1, k+1);
if (cine[i][j][k]){
System.out.println("Ocupado");
} else {
System.out.println("Libre");
}
}
}
}*/
do {
System.out.println("Impresión de Ocupación");
System.out.print("Sala [1-3]: ");
sala = teclado.nextInt();
System.out.printf("= Sala %d =\n", sala);
System.out.println(" [1][2][3][4][5][6][7][8][9][10]");
for(int j=0; j < 10; j++) {
System.out.printf("%d:", j + 1);
for (int k = 0; k < 10; k++) {
String estatus;
if (cine[sala - 1][j][k]) {
estatus = "X";
} else {
estatus = "_";
}
System.out.printf("[%s]", estatus);
}
System.out.println();
}
System.out.print("Desea revisar otra sala? [1-Sí / 0-No]");
opcion = teclado.nextInt();
} while (opcion != 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment