|
| 1 | +import java.util.Scanner; |
| 2 | + |
| 3 | +public class Main { |
| 4 | + |
| 5 | + private static final int FILAS = 4; |
| 6 | + private static final int COLUMNAS = 6; |
| 7 | + private static final int DIAS = 24; |
| 8 | + private boolean[] descubiertos = new boolean[DIAS]; |
| 9 | + |
| 10 | + public static void main(String[] args) { |
| 11 | + Main m = new Main(); |
| 12 | + Scanner sc = new Scanner(System.in); |
| 13 | + |
| 14 | + while (true) { |
| 15 | + m.dibujarCalendario(); |
| 16 | + System.out.print("Selecciona un día para descubrir (1-24) o 0 para salir: "); |
| 17 | + int dia = sc.nextInt(); |
| 18 | + if (dia == 0) break; |
| 19 | + m.seleccionarDia(dia); |
| 20 | + } |
| 21 | + |
| 22 | + sc.close(); |
| 23 | + } |
| 24 | + |
| 25 | + public void dibujarCalendario() { |
| 26 | + for (int i = 0; i < FILAS; i++) { |
| 27 | + for (int j = 0; j < COLUMNAS; j++) { |
| 28 | + int dia = i * COLUMNAS + j + 1; |
| 29 | + if (dia > DIAS) break; |
| 30 | + System.out.print("**** "); |
| 31 | + } |
| 32 | + System.out.println(); |
| 33 | + for (int j = 0; j < COLUMNAS; j++) { |
| 34 | + int dia = i * COLUMNAS + j + 1; |
| 35 | + if (dia > DIAS) break; |
| 36 | + if (descubiertos[dia - 1]) { |
| 37 | + System.out.print("**** "); |
| 38 | + } else { |
| 39 | + System.out.printf("*%02d* ", dia); |
| 40 | + } |
| 41 | + } |
| 42 | + System.out.println(); |
| 43 | + for (int j = 0; j < COLUMNAS; j++) { |
| 44 | + int dia = i * COLUMNAS + j + 1; |
| 45 | + if (dia > DIAS) break; |
| 46 | + System.out.print("**** "); |
| 47 | + } |
| 48 | + System.out.println(); |
| 49 | + System.out.println(); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public void seleccionarDia(int dia) { |
| 54 | + if (dia < 1 || dia > DIAS) { |
| 55 | + System.out.println("Día inválido."); |
| 56 | + return; |
| 57 | + } |
| 58 | + if (descubiertos[dia - 1]) { |
| 59 | + System.out.println("El día " + dia + " ya ha sido descubierto."); |
| 60 | + } else { |
| 61 | + descubiertos[dia - 1] = true; |
| 62 | + System.out.println("Has descubierto el día " + dia + "!"); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments