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); + } +} 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); + } +} 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 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 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"); + } + } + + } +}