|
| 1 | +import java.util.*; |
| 2 | +import java.util.concurrent.atomic.AtomicReference; |
| 3 | + |
| 4 | +/** |
| 5 | + * #36 EL SOMBRERO SELECCIONADOR |
| 6 | + * |
| 7 | + * @author martinbohorquez |
| 8 | + */ |
| 9 | +public class martinbohorquez { |
| 10 | + static List<QuestionAnswers> questionAnswers = new ArrayList<>(); |
| 11 | + static Map<House, Integer> houses = new LinkedHashMap<>(); |
| 12 | + static Scanner sc = new Scanner(System.in); |
| 13 | + |
| 14 | + public static void main(String[] args) { |
| 15 | + houses.put(House.FRONTED, 0); |
| 16 | + houses.put(House.BACKEND, 0); |
| 17 | + houses.put(House.MOBILE, 0); |
| 18 | + houses.put(House.DATA, 0); |
| 19 | + |
| 20 | + questionAnswers = setQuestions(); |
| 21 | + System.out.println(""" |
| 22 | + ¡Bienvenido a Hogwarts, la escuela de programación para magos y brujas del código! |
| 23 | + El sombrero seleccionador decidirá cuál es tu casa como programador. |
| 24 | + """); |
| 25 | + System.out.print("Indicar su nombre: "); |
| 26 | + String name = sc.nextLine(); |
| 27 | + |
| 28 | + displayQuestions(); |
| 29 | + displayResult(name); |
| 30 | + } |
| 31 | + |
| 32 | + private static List<QuestionAnswers> setQuestions() { |
| 33 | + // QuestionAnswers 1 |
| 34 | + String question1 = "¿Qué tipo de proyectos te interesa más desarrollar?"; |
| 35 | + List<Answer> answers1 = new ArrayList<>(List.of( |
| 36 | + new Answer("Interfaces visualmente atractivas y responsivas.", House.FRONTED), |
| 37 | + new Answer("Sistemas robustos y optimización de rendimiento del servidor.", House.BACKEND), |
| 38 | + new Answer("Aplicaciones móviles nativas para múltiples plataformas.", House.MOBILE), |
| 39 | + new Answer("Procesamiento y análisis de grandes volúmenes de datos.", House.DATA) |
| 40 | + )); |
| 41 | + Collections.shuffle(answers1); |
| 42 | + questionAnswers.add(new QuestionAnswers(question1, answers1)); |
| 43 | + |
| 44 | + // QuestionAnswers 2 |
| 45 | + String question2 = "¿En qué parte del ciclo de desarrollo te sientes más cómodo?"; |
| 46 | + List<Answer> answers2 = new ArrayList<>(List.of( |
| 47 | + new Answer("Creación de interfaces de usuario.", House.FRONTED), |
| 48 | + new Answer("Desarrollo de sistemas de backend.", House.BACKEND), |
| 49 | + new Answer("Diseño y arquitectura de bases de datos.", House.DATA), |
| 50 | + new Answer("Desarrollo de aplicaciones móviles con gran experiencia de usuario.", House.MOBILE) |
| 51 | + )); |
| 52 | + Collections.shuffle(answers2); |
| 53 | + questionAnswers.add(new QuestionAnswers(question2, answers2)); |
| 54 | + |
| 55 | + // QuestionAnswers 3 |
| 56 | + String question3 = "¿Qué herramienta prefieres usar en tu día a día?"; |
| 57 | + List<Answer> answers3 = new ArrayList<>(List.of( |
| 58 | + new Answer("Figma o Sketch para diseño UI/UX.", House.FRONTED), |
| 59 | + new Answer("Postman o cURL para probar APIs.", House.BACKEND), |
| 60 | + new Answer("SQL o Python para análisis de datos.", House.DATA), |
| 61 | + new Answer("Android Studio o Xcode.", House.MOBILE) |
| 62 | + )); |
| 63 | + Collections.shuffle(answers3); |
| 64 | + questionAnswers.add(new QuestionAnswers(question3, answers3)); |
| 65 | + |
| 66 | + // QuestionAnswers 4 |
| 67 | + String question4 = "¿Qué lenguaje de programación prefieres?"; |
| 68 | + List<Answer> answers4 = new ArrayList<>(List.of( |
| 69 | + new Answer("JavaScript o TypeScript.", House.FRONTED), |
| 70 | + new Answer("Java o Kotlin.", House.MOBILE), |
| 71 | + new Answer("Python o R.", House.DATA), |
| 72 | + new Answer("Java o Go.", House.BACKEND) |
| 73 | + )); |
| 74 | + Collections.shuffle(answers4); |
| 75 | + questionAnswers.add(new QuestionAnswers(question4, answers4)); |
| 76 | + |
| 77 | + // QuestionAnswers 5 |
| 78 | + String question5 = "¿Qué es lo que más disfrutas resolver en un proyecto?"; |
| 79 | + List<Answer> answers5 = new ArrayList<>(List.of( |
| 80 | + new Answer("Diseñar y construir pantallas interactivas.", House.FRONTED), |
| 81 | + new Answer("Optimizar la comunicación entre servidores y bases de datos.", House.BACKEND), |
| 82 | + new Answer("Extraer información valiosa de grandes conjuntos de datos.", House.DATA), |
| 83 | + new Answer("Optimizar el rendimiento de una aplicación móvil.", House.MOBILE) |
| 84 | + )); |
| 85 | + Collections.shuffle(answers5); |
| 86 | + questionAnswers.add(new QuestionAnswers(question5, answers5)); |
| 87 | + |
| 88 | + // QuestionAnswers 6 |
| 89 | + String question6 = "¿Qué consideras esencial para un proyecto exitoso?"; |
| 90 | + List<Answer> answers6 = new ArrayList<>(List.of( |
| 91 | + new Answer("Una interfaz intuitiva y atractiva.", House.FRONTED), |
| 92 | + new Answer("Un backend eficiente y seguro.", House.BACKEND), |
| 93 | + new Answer("Datos limpios y bien estructurados.", House.DATA), |
| 94 | + new Answer("Una aplicación móvil sin fallos y rápida.", House.MOBILE) |
| 95 | + )); |
| 96 | + Collections.shuffle(answers6); |
| 97 | + questionAnswers.add(new QuestionAnswers(question6, answers6)); |
| 98 | + |
| 99 | + // QuestionAnswers 7 |
| 100 | + String question7 = "¿Cómo prefieres abordar un problema complejo?"; |
| 101 | + List<Answer> answers7 = new ArrayList<>(List.of( |
| 102 | + new Answer("Dividiéndolo en pequeños componentes visuales.", House.FRONTED), |
| 103 | + new Answer("Optimizando el procesamiento del servidor.", House.BACKEND), |
| 104 | + new Answer("Modelando los datos de manera eficiente.", House.DATA), |
| 105 | + new Answer("Dividiendo la funcionalidad entre distintas plataformas móviles.", House.MOBILE) |
| 106 | + )); |
| 107 | + Collections.shuffle(answers7); |
| 108 | + questionAnswers.add(new QuestionAnswers(question7, answers7)); |
| 109 | + |
| 110 | + // QuestionAnswers 8 |
| 111 | + String question8 = "¿En qué contexto te sientes más productivo?"; |
| 112 | + List<Answer> answers8 = new ArrayList<>(List.of( |
| 113 | + new Answer("Diseñando interfaces responsivas.", House.FRONTED), |
| 114 | + new Answer("Construyendo APIs o microservicios.", House.BACKEND), |
| 115 | + new Answer("Analizando grandes volúmenes de datos.", House.DATA), |
| 116 | + new Answer("Desarrollando aplicaciones para Android o iOS.", House.MOBILE) |
| 117 | + )); |
| 118 | + Collections.shuffle(answers8); |
| 119 | + questionAnswers.add(new QuestionAnswers(question8, answers8)); |
| 120 | + |
| 121 | + // QuestionAnswers 9 |
| 122 | + String question9 = "¿Qué tecnología te gustaría dominar más?"; |
| 123 | + List<Answer> answers9 = new ArrayList<>(List.of( |
| 124 | + new Answer("React o Angular.", House.FRONTED), |
| 125 | + new Answer("Django o Spring Boot.", House.BACKEND), |
| 126 | + new Answer("Hadoop o Spark.", House.DATA), |
| 127 | + new Answer("Flutter o React Native.", House.MOBILE) |
| 128 | + )); |
| 129 | + Collections.shuffle(answers9); |
| 130 | + questionAnswers.add(new QuestionAnswers(question9, answers9)); |
| 131 | + |
| 132 | + // QuestionAnswers 10 |
| 133 | + String question10 = "¿Qué tipo de problemas te entusiasma resolver?"; |
| 134 | + List<Answer> answers10 = new ArrayList<>(List.of( |
| 135 | + new Answer("Hacer que las aplicaciones sean visualmente impactantes.", House.FRONTED), |
| 136 | + new Answer("Garantizar la seguridad y escalabilidad del sistema.", House.BACKEND), |
| 137 | + new Answer("Procesar y extraer conocimientos de datos complejos.", House.DATA), |
| 138 | + new Answer("Optimizar el rendimiento en aplicaciones móviles.", House.MOBILE) |
| 139 | + )); |
| 140 | + Collections.shuffle(answers10); |
| 141 | + questionAnswers.add(new QuestionAnswers(question10, answers10)); |
| 142 | + Collections.shuffle(questionAnswers); |
| 143 | + return questionAnswers; |
| 144 | + } |
| 145 | + |
| 146 | + private static void displayQuestions() { |
| 147 | + AtomicReference<Integer> id = new AtomicReference<>(1); |
| 148 | + questionAnswers.forEach(questionAnswers -> { |
| 149 | + AtomicReference<Integer> idA = new AtomicReference<>(1); |
| 150 | + while (true) { |
| 151 | + System.out.println("-".repeat(80)); |
| 152 | + System.out.printf("Pregunta %d: %s%n", id.get(), questionAnswers.question()); |
| 153 | + questionAnswers.answers.forEach(answer -> System.out.printf("%d. %s%n", |
| 154 | + idA.getAndSet(idA.get() + 1), answer.option())); |
| 155 | + System.out.print("Selecciona una respuesta entre 1 y 4: "); |
| 156 | + try { |
| 157 | + int choice = Integer.parseInt(sc.nextLine()); |
| 158 | + |
| 159 | + House house = questionAnswers.answers().get(choice - 1).house(); |
| 160 | + houses.replace(house, houses.get(house), houses.get(house) + 1); |
| 161 | + id.set(id.get() + 1); |
| 162 | + break; |
| 163 | + } catch (NumberFormatException | IndexOutOfBoundsException e) { |
| 164 | + idA.set(1); |
| 165 | + System.out.println("Esa opción no es valida! Volver a responder la pregunta."); |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + ); |
| 170 | + } |
| 171 | + |
| 172 | + private static void displayResult(String name) { |
| 173 | + House assignedHouse = Collections.max(houses.entrySet(), Map.Entry.comparingByValue()).getKey(); |
| 174 | + List<Integer> scores = houses.values().stream().toList(); |
| 175 | + System.out.println("-".repeat(80)); |
| 176 | + System.out.println("<----- RESULTADOS DEL TEST ----->"); |
| 177 | + System.out.println("Tus preferencias son:"); |
| 178 | + houses.forEach((house, integer) -> |
| 179 | + System.out.println(house + " -> " + ("|" + house.getEmoji() + "|").repeat(integer))); |
| 180 | + |
| 181 | + Integer maxScore = scores.stream().max(Integer::compareTo).orElse(null); |
| 182 | + List<Integer> maxScores = scores.stream().filter(s -> s.equals(maxScore)).toList(); |
| 183 | + if (maxScores.size() > 1) { |
| 184 | + |
| 185 | + Random random = new Random(); |
| 186 | + assignedHouse = new ArrayList<>(houses.entrySet().stream() |
| 187 | + .filter(houseIntegerEntry -> houseIntegerEntry.getValue().equals(maxScore)) |
| 188 | + .map(Map.Entry::getKey) |
| 189 | + .toList()) |
| 190 | + .get(random.nextInt(0, maxScores.size())); |
| 191 | + System.out.printf(""" |
| 192 | + Hmmm... Ha sido una decisión muy complicada %s. |
| 193 | + ¡Pero finalmente tu casa será %s [%s] |
| 194 | + """, name, assignedHouse, assignedHouse.getEmoji()); |
| 195 | + } else { |
| 196 | + System.out.printf(""" |
| 197 | + Hmmm... Enhorabuena %s. |
| 198 | + ¡Tu casa será %s [%s] |
| 199 | + """, name, assignedHouse, assignedHouse.getEmoji()); |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + private record QuestionAnswers(String question, List<Answer> answers) { |
| 204 | + } |
| 205 | + |
| 206 | + private record Answer(String option, House house) { |
| 207 | + } |
| 208 | + |
| 209 | + private enum House { |
| 210 | + FRONTED("Fronted", "🌐"), |
| 211 | + BACKEND("Backend", "💻"), |
| 212 | + MOBILE("Mobile", "📲"), |
| 213 | + DATA("Data", "📊"); |
| 214 | + |
| 215 | + private final String displayName; |
| 216 | + private final String emoji; |
| 217 | + |
| 218 | + House(String displayName, String emoji) { |
| 219 | + this.displayName = displayName; |
| 220 | + this.emoji = emoji; |
| 221 | + } |
| 222 | + |
| 223 | + public String getEmoji() { |
| 224 | + return emoji; |
| 225 | + } |
| 226 | + |
| 227 | + @Override |
| 228 | + public String toString() { |
| 229 | + return displayName; |
| 230 | + } |
| 231 | + } |
| 232 | +} |
0 commit comments