From 288adcafcc643d0f721e10b643acb442c49e6c52 Mon Sep 17 00:00:00 2001 From: johnalexguerrero Date: Fri, 29 Nov 2024 17:44:45 -0500 Subject: [PATCH 1/7] Reto#47-Java --- .../java/JohnAlexGuerrero/.gitignore | 38 ++++++++ .../src/main/java/org/example/Main.java | 92 +++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/.gitignore create mode 100644 Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/src/main/java/org/example/Main.java diff --git a/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/.gitignore b/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/.gitignore new file mode 100644 index 0000000000..5ff6309b71 --- /dev/null +++ b/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/src/main/java/org/example/Main.java b/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/src/main/java/org/example/Main.java new file mode 100644 index 0000000000..c2918fc63b --- /dev/null +++ b/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/src/main/java/org/example/Main.java @@ -0,0 +1,92 @@ +package org.example; + +import java.util.Scanner; + +// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, +// then press Enter. You can now see whitespace characters in your code. +public class Main { + // * - El calendario mostrará los días del 1 al 24 repartidos + // * en 6 columnas a modo de cuadrícula. + //- Cada cuadrícula correspondiente a un día tendrá un tamaño + // * de 4x3 caracteres, y sus bordes serán asteríscos. + //* Ejemplo de cuadrículas: + //* **** **** **** + //* *01* *02* *03* ... + //* **** **** **** + static int [][] calendar = { + {1,2,3,4,5,6}, {7,8,9,10,11,12}, {13,14,15,16,17,18}, {19,20,21,22,23,24} + }; + + public static void showCalendar(){ + for(int[] row: calendar){ + System.out.println("**** **** **** **** **** **** "); + for(int i: row){ + String day = (i < 10)? "0"+i : ""+i; + if(i == 0){ + day = "**"; + } + System.out.printf("*"+day+"* "); + } + System.out.println(); + } + System.out.println("**** **** **** **** **** **** "); + System.out.println(); + } + + public static boolean avalableDay(int d){ + for (int i = 0; i < calendar.length; i++){ + for (int j = 0; j < calendar[i].length; j++){ + if(calendar[i][j] == d){ + selectDayInCalendar(i,j); + return true; + } + } + } + return false; + } + + public static void selectDayInCalendar(int indexX, int indexY){ + // * cubierta de asteríscos (sin mostrar el día). + // * Ejemplo de selección del día 1 + // * **** **** **** + // * **** *02* *03* ... + // * **** **** **** + calendar[indexX][indexY] = 0; + } + + public static void main(String[] args) { + // Press Alt+Intro with your caret at the highlighted text to see how + Scanner scanner = new Scanner(System.in); + boolean flag = true; + + while(flag){ + showCalendar(); + //* - El usuario seleccioná qué día quiere descubrir. + System.out.println("select one day or exit: "); + String selectDay = scanner.nextLine(); + + if(selectDay.equals("exit")){ + flag = false; + } + + try{ + int selectedDay = Integer.parseInt(selectDay); + + //Si está sin descubrir, se le dirá que ha abierto ese día + if(avalableDay(selectedDay)){ + System.out.println("This day is avalable."); + }else{ + //* - Si se selecciona un número ya descubierto, se le notifica + // * al usuario. + System.out.println("Day is not avalable."); + } + + }catch(NumberFormatException ex){ + System.out.println("select on number."); + } + } + + // * y se mostrará de nuevo el calendario con esa cuadrícula + + } +} \ No newline at end of file From 72b44c9f5b45c9fd0bc11e0c328a55d551c0b763 Mon Sep 17 00:00:00 2001 From: johnalexguerrero Date: Mon, 2 Dec 2024 16:14:52 -0500 Subject: [PATCH 2/7] #46-Java --- .../java/JohnAlexGuerrero/.gitignore | 38 ++++++ .../src/main/java/org/example/Main.java | 113 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/.gitignore create mode 100644 Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/src/main/java/org/example/Main.java diff --git a/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/.gitignore b/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/.gitignore new file mode 100644 index 0000000000..5ff6309b71 --- /dev/null +++ b/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/src/main/java/org/example/Main.java b/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/src/main/java/org/example/Main.java new file mode 100644 index 0000000000..823c966d58 --- /dev/null +++ b/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/src/main/java/org/example/Main.java @@ -0,0 +1,113 @@ +package org.example; + +import java.util.HashSet; +import java.util.Objects; + +// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, +// then press Enter. You can now see whitespace characters in your code. +public class Main { + public static void main(String[] args) { + SocialNetwork socialnetwork = new SocialNetwork(); + + //- Registrar un usuario por defecto con nombre e identificador único. + socialnetwork.registerUser("u123", "alexander guerrero"); + socialnetwork.registerUser("u456", "sandra estacio"); + socialnetwork.registerUser("u467", "carolina maigual"); + socialnetwork.registerUser("u897", "mileidy cruz"); + socialnetwork.registerUser("u230", "daniel botina"); + socialnetwork.registerUser("u239", "diego botina"); + socialnetwork.registerUser("u348", "gloria maigual"); + socialnetwork.registerUser("u438", "teresa maigual"); + socialnetwork.registerUser("u489", "alejandra rojas"); + + //- Seleccionar un usuario + User u1 = socialnetwork.getUser("u489"); + //- Un usuario puede seguir/dejar de seguir a otro. + u1.followUser("u348"); + u1.followUser("u467"); + u1.followUser("u897"); + + //- Mostrar usuarios + for (User user : socialnetwork.getUsers()) { + System.out.println(user.toString()); + } + } +} + +class SocialNetwork{ + private static HashSet users; + public SocialNetwork() { + users = new HashSet<>(); + } + public void registerUser(String id, String name){ + users.add(new User(id, name)); + } + public User getUser(String id){ + for(User user: users){ + if(user.getId().equals(id)){ + return user; + } + } + return null; + } + public void unfollowUser(){} + public HashSet getUsers() { + return users; + } +} + +class User{ + private String id; + private String name; + private HashSet followers; + private HashSet following; + public void followUser(String followIdUser){ + followers.add(followIdUser); + } + + public User(String id, String name) { + this.id = id; + this.name = name; + this.followers = new HashSet(); + this.following = new HashSet(); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public HashSet getFollowers() { + return followers; + } + + public HashSet getFollowing() { + return following; + } + + @Override + public String toString() { + return "User{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", followers=" + followers + + ", following=" + following + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + User user = (User) o; + return Objects.equals(id, user.id) && Objects.equals(name, user.name) && Objects.equals(followers, user.followers) && Objects.equals(following, user.following); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, followers, following); + } +} From c59e8886b1c02156ebaf08711ac0539712af26c5 Mon Sep 17 00:00:00 2001 From: johnalexguerrero Date: Fri, 6 Dec 2024 10:09:13 -0500 Subject: [PATCH 3/7] Reto#48-java --- .../java/JohnAlexGuerrero.java" | 237 ++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 "Roadmap/48 - \303\201RBOL DE NAVIDAD/java/JohnAlexGuerrero.java" diff --git "a/Roadmap/48 - \303\201RBOL DE NAVIDAD/java/JohnAlexGuerrero.java" "b/Roadmap/48 - \303\201RBOL DE NAVIDAD/java/JohnAlexGuerrero.java" new file mode 100644 index 0000000000..7685d4c5d9 --- /dev/null +++ "b/Roadmap/48 - \303\201RBOL DE NAVIDAD/java/JohnAlexGuerrero.java" @@ -0,0 +1,237 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.mycompany.christmastree; + +import java.util.Scanner; + +/** + * + * @author JOHN + */ +public class ChristmasTree { + static class Tree{ + private String treeDraw; + private int column; + private int row; + private boolean star; + private boolean onLight; + private int balls; + private int lights; + + public Tree(int heigth, boolean star) { + this.setColumn(heigth); + this.setRow(heigth); + this.star = star; + this.balls = 0; + this.lights = 0; + this.treeDraw = ""; + } + + public void setRow(int h){ + this.row = h; + } + + public void setColumn(int h){ + for(int i=0; i 0 && (i+1)%2 == 0 ){ + tree += "o"; + amountBall -= 1; + }else if(amountLight > 0 && (i+1)%3 == 0 && this.isOnLight()){ + tree += "+"; + amountLight -= 1; + }else{ + tree += "*"; + } + } + } + } + } + + //base + for(int k=0; k Date: Fri, 6 Dec 2024 10:32:26 -0500 Subject: [PATCH 4/7] Reto#47-java --- .../java/JohnAlexGuerrero/.gitignore | 38 -------- .../src/main/java/org/example/Main.java | 92 ------------------- 2 files changed, 130 deletions(-) delete mode 100644 Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/.gitignore delete mode 100644 Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/src/main/java/org/example/Main.java diff --git a/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/.gitignore b/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/.gitignore deleted file mode 100644 index 5ff6309b71..0000000000 --- a/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/src/main/java/org/example/Main.java b/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/src/main/java/org/example/Main.java deleted file mode 100644 index c2918fc63b..0000000000 --- a/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero/src/main/java/org/example/Main.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.example; - -import java.util.Scanner; - -// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, -// then press Enter. You can now see whitespace characters in your code. -public class Main { - // * - El calendario mostrará los días del 1 al 24 repartidos - // * en 6 columnas a modo de cuadrícula. - //- Cada cuadrícula correspondiente a un día tendrá un tamaño - // * de 4x3 caracteres, y sus bordes serán asteríscos. - //* Ejemplo de cuadrículas: - //* **** **** **** - //* *01* *02* *03* ... - //* **** **** **** - static int [][] calendar = { - {1,2,3,4,5,6}, {7,8,9,10,11,12}, {13,14,15,16,17,18}, {19,20,21,22,23,24} - }; - - public static void showCalendar(){ - for(int[] row: calendar){ - System.out.println("**** **** **** **** **** **** "); - for(int i: row){ - String day = (i < 10)? "0"+i : ""+i; - if(i == 0){ - day = "**"; - } - System.out.printf("*"+day+"* "); - } - System.out.println(); - } - System.out.println("**** **** **** **** **** **** "); - System.out.println(); - } - - public static boolean avalableDay(int d){ - for (int i = 0; i < calendar.length; i++){ - for (int j = 0; j < calendar[i].length; j++){ - if(calendar[i][j] == d){ - selectDayInCalendar(i,j); - return true; - } - } - } - return false; - } - - public static void selectDayInCalendar(int indexX, int indexY){ - // * cubierta de asteríscos (sin mostrar el día). - // * Ejemplo de selección del día 1 - // * **** **** **** - // * **** *02* *03* ... - // * **** **** **** - calendar[indexX][indexY] = 0; - } - - public static void main(String[] args) { - // Press Alt+Intro with your caret at the highlighted text to see how - Scanner scanner = new Scanner(System.in); - boolean flag = true; - - while(flag){ - showCalendar(); - //* - El usuario seleccioná qué día quiere descubrir. - System.out.println("select one day or exit: "); - String selectDay = scanner.nextLine(); - - if(selectDay.equals("exit")){ - flag = false; - } - - try{ - int selectedDay = Integer.parseInt(selectDay); - - //Si está sin descubrir, se le dirá que ha abierto ese día - if(avalableDay(selectedDay)){ - System.out.println("This day is avalable."); - }else{ - //* - Si se selecciona un número ya descubierto, se le notifica - // * al usuario. - System.out.println("Day is not avalable."); - } - - }catch(NumberFormatException ex){ - System.out.println("select on number."); - } - } - - // * y se mostrará de nuevo el calendario con esa cuadrícula - - } -} \ No newline at end of file From 4941085b4d0f76c44e7d436eb266466afa6acac8 Mon Sep 17 00:00:00 2001 From: johnalexguerrero Date: Fri, 6 Dec 2024 10:43:48 -0500 Subject: [PATCH 5/7] Reto#46-java --- .../java/JohnAlexGuerrero.java | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero.java diff --git a/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero.java b/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero.java new file mode 100644 index 0000000000..823c966d58 --- /dev/null +++ b/Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero.java @@ -0,0 +1,113 @@ +package org.example; + +import java.util.HashSet; +import java.util.Objects; + +// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, +// then press Enter. You can now see whitespace characters in your code. +public class Main { + public static void main(String[] args) { + SocialNetwork socialnetwork = new SocialNetwork(); + + //- Registrar un usuario por defecto con nombre e identificador único. + socialnetwork.registerUser("u123", "alexander guerrero"); + socialnetwork.registerUser("u456", "sandra estacio"); + socialnetwork.registerUser("u467", "carolina maigual"); + socialnetwork.registerUser("u897", "mileidy cruz"); + socialnetwork.registerUser("u230", "daniel botina"); + socialnetwork.registerUser("u239", "diego botina"); + socialnetwork.registerUser("u348", "gloria maigual"); + socialnetwork.registerUser("u438", "teresa maigual"); + socialnetwork.registerUser("u489", "alejandra rojas"); + + //- Seleccionar un usuario + User u1 = socialnetwork.getUser("u489"); + //- Un usuario puede seguir/dejar de seguir a otro. + u1.followUser("u348"); + u1.followUser("u467"); + u1.followUser("u897"); + + //- Mostrar usuarios + for (User user : socialnetwork.getUsers()) { + System.out.println(user.toString()); + } + } +} + +class SocialNetwork{ + private static HashSet users; + public SocialNetwork() { + users = new HashSet<>(); + } + public void registerUser(String id, String name){ + users.add(new User(id, name)); + } + public User getUser(String id){ + for(User user: users){ + if(user.getId().equals(id)){ + return user; + } + } + return null; + } + public void unfollowUser(){} + public HashSet getUsers() { + return users; + } +} + +class User{ + private String id; + private String name; + private HashSet followers; + private HashSet following; + public void followUser(String followIdUser){ + followers.add(followIdUser); + } + + public User(String id, String name) { + this.id = id; + this.name = name; + this.followers = new HashSet(); + this.following = new HashSet(); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public HashSet getFollowers() { + return followers; + } + + public HashSet getFollowing() { + return following; + } + + @Override + public String toString() { + return "User{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", followers=" + followers + + ", following=" + following + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + User user = (User) o; + return Objects.equals(id, user.id) && Objects.equals(name, user.name) && Objects.equals(followers, user.followers) && Objects.equals(following, user.following); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, followers, following); + } +} From b878df743156baf3952e15d6ef19def23122f2ed Mon Sep 17 00:00:00 2001 From: johnalexguerrero Date: Wed, 11 Dec 2024 21:20:07 -0500 Subject: [PATCH 6/7] Reto#49 - Java --- .../java/JohnAlexGuerrero.java" | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 "Roadmap/49 - EL ALMAC\303\211N DE PAP\303\201 NOEL/java/JohnAlexGuerrero.java" diff --git "a/Roadmap/49 - EL ALMAC\303\211N DE PAP\303\201 NOEL/java/JohnAlexGuerrero.java" "b/Roadmap/49 - EL ALMAC\303\211N DE PAP\303\201 NOEL/java/JohnAlexGuerrero.java" new file mode 100644 index 0000000000..afa1f743ba --- /dev/null +++ "b/Roadmap/49 - EL ALMAC\303\211N DE PAP\303\201 NOEL/java/JohnAlexGuerrero.java" @@ -0,0 +1,142 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.mycompany.codesecretchristmas; + +import java.util.HashSet; +import java.util.Scanner; +import java.util.Set; + +/** + * + * @author JOHN + * * EJERCICIO: + * Papá Noel tiene que comenzar a repartir los regalos... + * ¡Pero ha olvidado el código secreto de apertura del almacén! + * + * Crea un programa donde introducir códigos y obtener pistas. + * + * Código: + * x El código es una combinación de letras y números aleatorios + * de longitud 4. (Letras: de la A a la C, Números: del 1 al 3) + * x No hay repetidos. + * x Se genera de manera aleatoria al iniciar el programa. + * + * Usuario: + * x Dispone de 10 intentos para acertarlo. + * x En cada turno deberá escribir un código de 4 caracteres, y + * el programa le indicará para cada uno lo siguiente: + * - Correcto: Si el caracter está en la posición correcta. + * - Presente: Si el caracter existe, pero esa no es su posición. + * - Incorrecto: Si el caracter no existe en el código secreto. + * - Deben controlarse errores de longitud y caracteres soportados. + * + * Finalización: + * - Papa Noel gana si descrifra el código antes de 10 intentos. + * - Pierde si no lo logra, ya que no podría entregar los regalos. + + */ + +public class CodeSecretChristmas { + static int attemps = 10; + + public static String[] getLetters(){ + String[] letters = {"A","B","C","1","2","3"}; + + return letters; + } + + public static String generatedKey(){ + Set key = new HashSet<>(); + String[] ls = getLetters(); + + while(key.size() < 4){ + int number = (int) (Math.random()* ls.length); + key.add(ls[number]); + } + String s = String.join("", key); + + return s; + } + + + public static String validKey(String keyGenerated, char character, int index){ + String flap = ""; + if(keyGenerated.charAt(index) == character && keyGenerated.indexOf(""+character) == index){ + flap = "c"; + }else if(keyGenerated.contains(""+character)){ + flap = "p"; + }else{ + flap = "i"; + } + return flap; + } + + public static boolean isValid(String code){ + boolean f = false; + for(int x=0; x < getLetters().length; x++){ + if(code.contains(getLetters()[x])){ + f = true; + }else{ + f = false; + } + } + + return f; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + String code; + String keyGenerated = generatedKey(); + + System.out.println("Almacen de Santa"); + + while(attemps < 11){ + + System.out.println("Ingresa codigo de seguridad: "); + code = scanner.nextLine().toUpperCase(); + + while(!isValid(code)){ + System.out.println("Ingresa codigo de seguridad (A,B,C y 1, 2, 3): "); + code = scanner.nextLine().toUpperCase(); + System.out.println("Hay uno o mas caracter(es) que no son permitidos"); + System.out.printf("son permitidos: "); + for(String k: getLetters()){ + System.out.printf(k+", "); + + } + System.out.println(""); + } + + + if(code.length() == 4){ + for(int i=0; i<4; i++){ + switch(validKey(keyGenerated,code.charAt(i), i)){ + case "c": + System.out.println("Correcto: "+code.charAt(i)); + break; + case "p": + System.out.println("Presente: "+code.charAt(i)); + break; + case "i": + System.out.println(code.charAt(i)+ " No concuerda con el codigo generado."); + break; + } + } + }else{ + System.out.println("el codigo debe contener solo 4 caracteres"); + System.out.println("codigo: "+code.toLowerCase()); + } + + if(keyGenerated.equals(""+code)){ + System.out.println("Acceso concedido clave: "+keyGenerated); + }else{ + attemps -= 1; + System.out.println("Te quedan #"+attemps+" intentos"); + } + } + + } +} From 3ca49974239fd60543ebd5a4a24ac98a52269b36 Mon Sep 17 00:00:00 2001 From: johnalexguerrero Date: Wed, 11 Dec 2024 21:28:19 -0500 Subject: [PATCH 7/7] Reto#47 -java --- .../java/JohnAlexGuerrero.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero.java diff --git a/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero.java b/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero.java new file mode 100644 index 0000000000..c2918fc63b --- /dev/null +++ b/Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero.java @@ -0,0 +1,92 @@ +package org.example; + +import java.util.Scanner; + +// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, +// then press Enter. You can now see whitespace characters in your code. +public class Main { + // * - El calendario mostrará los días del 1 al 24 repartidos + // * en 6 columnas a modo de cuadrícula. + //- Cada cuadrícula correspondiente a un día tendrá un tamaño + // * de 4x3 caracteres, y sus bordes serán asteríscos. + //* Ejemplo de cuadrículas: + //* **** **** **** + //* *01* *02* *03* ... + //* **** **** **** + static int [][] calendar = { + {1,2,3,4,5,6}, {7,8,9,10,11,12}, {13,14,15,16,17,18}, {19,20,21,22,23,24} + }; + + public static void showCalendar(){ + for(int[] row: calendar){ + System.out.println("**** **** **** **** **** **** "); + for(int i: row){ + String day = (i < 10)? "0"+i : ""+i; + if(i == 0){ + day = "**"; + } + System.out.printf("*"+day+"* "); + } + System.out.println(); + } + System.out.println("**** **** **** **** **** **** "); + System.out.println(); + } + + public static boolean avalableDay(int d){ + for (int i = 0; i < calendar.length; i++){ + for (int j = 0; j < calendar[i].length; j++){ + if(calendar[i][j] == d){ + selectDayInCalendar(i,j); + return true; + } + } + } + return false; + } + + public static void selectDayInCalendar(int indexX, int indexY){ + // * cubierta de asteríscos (sin mostrar el día). + // * Ejemplo de selección del día 1 + // * **** **** **** + // * **** *02* *03* ... + // * **** **** **** + calendar[indexX][indexY] = 0; + } + + public static void main(String[] args) { + // Press Alt+Intro with your caret at the highlighted text to see how + Scanner scanner = new Scanner(System.in); + boolean flag = true; + + while(flag){ + showCalendar(); + //* - El usuario seleccioná qué día quiere descubrir. + System.out.println("select one day or exit: "); + String selectDay = scanner.nextLine(); + + if(selectDay.equals("exit")){ + flag = false; + } + + try{ + int selectedDay = Integer.parseInt(selectDay); + + //Si está sin descubrir, se le dirá que ha abierto ese día + if(avalableDay(selectedDay)){ + System.out.println("This day is avalable."); + }else{ + //* - Si se selecciona un número ya descubierto, se le notifica + // * al usuario. + System.out.println("Day is not avalable."); + } + + }catch(NumberFormatException ex){ + System.out.println("select on number."); + } + } + + // * y se mostrará de nuevo el calendario con esa cuadrícula + + } +} \ No newline at end of file