Skip to content

#47 - Java #7230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Roadmap/47 - CALENDARIO DE ADVIENTO/java/asjordi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import java.util.Scanner;

public class Main {

private static final int FILAS = 4;
private static final int COLUMNAS = 6;
private static final int DIAS = 24;
private boolean[] descubiertos = new boolean[DIAS];

public static void main(String[] args) {
Main m = new Main();
Scanner sc = new Scanner(System.in);

while (true) {
m.dibujarCalendario();
System.out.print("Selecciona un día para descubrir (1-24) o 0 para salir: ");
int dia = sc.nextInt();
if (dia == 0) break;
m.seleccionarDia(dia);
}

sc.close();
}

public void dibujarCalendario() {
for (int i = 0; i < FILAS; i++) {
for (int j = 0; j < COLUMNAS; j++) {
int dia = i * COLUMNAS + j + 1;
if (dia > DIAS) break;
System.out.print("**** ");
}
System.out.println();
for (int j = 0; j < COLUMNAS; j++) {
int dia = i * COLUMNAS + j + 1;
if (dia > DIAS) break;
if (descubiertos[dia - 1]) {
System.out.print("**** ");
} else {
System.out.printf("*%02d* ", dia);
}
}
System.out.println();
for (int j = 0; j < COLUMNAS; j++) {
int dia = i * COLUMNAS + j + 1;
if (dia > DIAS) break;
System.out.print("**** ");
}
System.out.println();
System.out.println();
}
}

public void seleccionarDia(int dia) {
if (dia < 1 || dia > DIAS) {
System.out.println("Día inválido.");
return;
}
if (descubiertos[dia - 1]) {
System.out.println("El día " + dia + " ya ha sido descubierto.");
} else {
descubiertos[dia - 1] = true;
System.out.println("Has descubierto el día " + dia + "!");
}
}
}