├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── main.yml ├── .gitignore ├── .vscode ├── launch.json └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md └── src └── es └── dsrroma └── school └── java └── desafio1 ├── video01_01 ├── GeneradorBoletoSimple.java └── GeneradorBoletoSimple2.java ├── video01_02 ├── Boleto.java └── GeneradorBoletoReintegro.java ├── video01_03 ├── ColumnaBingo.java ├── GeneradorTableroBingo.java ├── LetraBingo.java └── TableroBingo.java ├── video01_04 ├── SorteoNavidad.java └── TipoPremio.java ├── video01_05 └── ValidadorBoletoSimple.java ├── video01_06 ├── Boleto.java ├── Premio.java └── ValidadorBoletoReintegro.java ├── video01_07 └── SorteoBingo.java ├── video01_08 └── FormateadorFechas.java ├── video01_09 └── EdadExacta.java ├── video01_10 └── ContadorLetras.java ├── video01_11 └── RellenarMatriz.java ├── video01_12 └── SumarMatrices.java ├── video01_13 └── MultiplicarMatrices.java ├── video01_14 └── CalcularMinimo.java ├── video01_15 └── CalcularMedia.java ├── video01_16 └── BuscarSinOrden.java ├── video01_17 └── BuscarConOrden.java └── video01_18 ├── EsHoraDePlanchar.java └── Tarifa.java /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.236.0/containers/java/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster 4 | ARG VARIANT="17-bullseye" 5 | FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT} 6 | 7 | # [Option] Install Maven 8 | ARG INSTALL_MAVEN="false" 9 | ARG MAVEN_VERSION="" 10 | # [Option] Install Gradle 11 | ARG INSTALL_GRADLE="false" 12 | ARG GRADLE_VERSION="" 13 | RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \ 14 | && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi 15 | 16 | # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 17 | ARG NODE_VERSION="none" 18 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 19 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Java", 3 | "build": { 4 | "dockerfile": "Dockerfile", 5 | "args": { 6 | "VARIANT": "17", //Can change to another of Java 7 | "INSTALL_MAVEN": "false", 8 | "INSTALL_GRADLE": "false", 9 | "NODE_VERSION": "lts/*" 10 | } 11 | }, 12 | 13 | // Configure tool-specific properties. 14 | "customizations": { 15 | "vscode": { 16 | "settings": { 17 | "java.home": "/docker-java-home" 18 | }, 19 | "extensions": [ 20 | "vscjava.vscode-java-pack", 21 | "GitHub.github-vscode-theme" 22 | ] 23 | } 24 | }, 25 | "remoteUser": "vscode", 26 | "onCreateCommand": "echo PS1='\"$ \"' >> ~/.bashrc" //Set Terminal Prompt to $ 27 | } 28 | 29 | // DevContainer Reference: https://code.visualstudio.com/docs/remote/devcontainerjson-reference 30 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners for these exercise files: 2 | # * (asterisk) denotes "all files and folders" 3 | # Example: * @producer @instructor 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Issue Overview 9 | 10 | 11 | ## Describe your environment 12 | 13 | 14 | ## Steps to Reproduce 15 | 16 | 1. 17 | 2. 18 | 3. 19 | 4. 20 | 21 | ## Expected Behavior 22 | 23 | 24 | ## Current Behavior 25 | 26 | 27 | ## Possible Solution 28 | 29 | 30 | ## Screenshots / Video 31 | 32 | 33 | ## Related Issues 34 | 35 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Copy To Branches 2 | on: 3 | workflow_dispatch: 4 | jobs: 5 | copy-to-branches: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | with: 10 | fetch-depth: 0 11 | - name: Copy To Branches Action 12 | uses: planetoftheweb/copy-to-branches@v1.2 13 | env: 14 | key: main 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | .tmp 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "java", 9 | "name": "Launch Current File", 10 | "request": "launch", 11 | "mainClass": "${file}" 12 | }, 13 | { 14 | "type": "java", 15 | "name": "Launch GeneradorBoletoSimple", 16 | "request": "launch", 17 | "mainClass": "es.dsrroma.school.java.desafio1.video01_01.GeneradorBoletoSimple", 18 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 19 | }, 20 | { 21 | "type": "java", 22 | "name": "Launch GeneradorBoletoSimple2", 23 | "request": "launch", 24 | "mainClass": "es.dsrroma.school.java.desafio1.video01_01.GeneradorBoletoSimple2", 25 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 26 | }, 27 | { 28 | "type": "java", 29 | "name": "Launch GeneradorBoletoReintegro", 30 | "request": "launch", 31 | "mainClass": "es.dsrroma.school.java.desafio1.video01_02.GeneradorBoletoReintegro", 32 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 33 | }, 34 | { 35 | "type": "java", 36 | "name": "Launch GeneradorTableroBingo", 37 | "request": "launch", 38 | "mainClass": "es.dsrroma.school.java.desafio1.video01_03.GeneradorTableroBingo", 39 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 40 | }, 41 | { 42 | "type": "java", 43 | "name": "Launch SorteoNavidad", 44 | "request": "launch", 45 | "mainClass": "es.dsrroma.school.java.desafio1.video01_04.SorteoNavidad", 46 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 47 | }, 48 | { 49 | "type": "java", 50 | "name": "Launch ValidadorBoletoSimple", 51 | "request": "launch", 52 | "mainClass": "es.dsrroma.school.java.desafio1.video01_05.ValidadorBoletoSimple", 53 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 54 | }, 55 | { 56 | "type": "java", 57 | "name": "Launch ValidadorBoletoReintegro", 58 | "request": "launch", 59 | "mainClass": "es.dsrroma.school.java.desafio1.video01_06.ValidadorBoletoReintegro", 60 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 61 | }, 62 | { 63 | "type": "java", 64 | "name": "Launch SorteoBingo", 65 | "request": "launch", 66 | "mainClass": "es.dsrroma.school.java.desafio1.video01_07.SorteoBingo", 67 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 68 | }, 69 | { 70 | "type": "java", 71 | "name": "Launch FormateadorFechas", 72 | "request": "launch", 73 | "mainClass": "es.dsrroma.school.java.desafio1.video01_08.FormateadorFechas", 74 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 75 | }, 76 | { 77 | "type": "java", 78 | "name": "Launch EdadExacta", 79 | "request": "launch", 80 | "mainClass": "es.dsrroma.school.java.desafio1.video01_09.EdadExacta", 81 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 82 | }, 83 | { 84 | "type": "java", 85 | "name": "Launch ContadorLetras", 86 | "request": "launch", 87 | "args": ["patata"], 88 | "mainClass": "es.dsrroma.school.java.desafio1.video01_10.ContadorLetras", 89 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 90 | }, 91 | { 92 | "type": "java", 93 | "name": "Launch RellenarMatriz", 94 | "request": "launch", 95 | "args": ["3", "6"], 96 | "mainClass": "es.dsrroma.school.java.desafio1.video01_11.RellenarMatriz", 97 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 98 | }, 99 | { 100 | "type": "java", 101 | "name": "Launch SumarMatrices", 102 | "request": "launch", 103 | "mainClass": "es.dsrroma.school.java.desafio1.video01_12.SumarMatrices", 104 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 105 | }, 106 | { 107 | "type": "java", 108 | "name": "Launch MultiplicarMatrices", 109 | "request": "launch", 110 | "mainClass": "es.dsrroma.school.java.desafio1.video01_13.MultiplicarMatrices", 111 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 112 | }, 113 | { 114 | "type": "java", 115 | "name": "Launch CalcularMinimo", 116 | "request": "launch", 117 | "mainClass": "es.dsrroma.school.java.desafio1.video01_14.CalcularMinimo", 118 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 119 | }, 120 | { 121 | "type": "java", 122 | "name": "Launch CalcularMedia", 123 | "request": "launch", 124 | "mainClass": "es.dsrroma.school.java.desafio1.video01_15.CalcularMedia", 125 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 126 | }, 127 | { 128 | "type": "java", 129 | "name": "Launch BuscarSinOrden", 130 | "request": "launch", 131 | "mainClass": "es.dsrroma.school.java.desafio1.video01_16.BuscarSinOrden", 132 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 133 | }, 134 | { 135 | "type": "java", 136 | "name": "Launch BuscarConOrden", 137 | "request": "launch", 138 | "mainClass": "es.dsrroma.school.java.desafio1.video01_17.BuscarConOrden", 139 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 140 | }, 141 | { 142 | "type": "java", 143 | "name": "Launch EsHoraDePlanchar", 144 | "request": "launch", 145 | "mainClass": "es.dsrroma.school.java.desafio1.video01_18.EsHoraDePlanchar", 146 | "projectName": "desafio_programacion_java_2498412_4025d3f0" 147 | } 148 | ] 149 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.bracketPairColorization.enabled": true, 3 | "editor.cursorBlinking": "solid", 4 | "editor.fontFamily": "ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace", 5 | "editor.fontLigatures": false, 6 | "editor.fontSize": 22, 7 | "editor.formatOnPaste": true, 8 | "editor.formatOnSave": true, 9 | "editor.lineNumbers": "on", 10 | "editor.matchBrackets": "always", 11 | "editor.minimap.enabled": false, 12 | "editor.smoothScrolling": true, 13 | "editor.tabSize": 2, 14 | "editor.useTabStops": true, 15 | "emmet.triggerExpansionOnTab": true, 16 | "explorer.openEditors.visible": 0, 17 | "files.autoSave": "afterDelay", 18 | "screencastMode.onlyKeyboardShortcuts": true, 19 | "terminal.integrated.fontSize": 18, 20 | "workbench.activityBar.visible": true, 21 | "workbench.colorTheme": "Visual Studio Dark", 22 | "workbench.fontAliasing": "antialiased", 23 | "workbench.statusBar.visible": true, 24 | "java.server.launchMode": "Standard" 25 | } 26 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contribution Agreement 3 | ====================== 4 | 5 | This repository does not accept pull requests (PRs). All pull requests will be closed. 6 | 7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license. 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | LinkedIn Learning Exercise Files License Agreement 2 | ================================================== 3 | 4 | This License Agreement (the "Agreement") is a binding legal agreement 5 | between you (as an individual or entity, as applicable) and LinkedIn 6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning 7 | exercise files in this repository (“Licensed Materials”), you agree to 8 | be bound by the terms of this Agreement. If you do not agree to these 9 | terms, do not download or use the Licensed Materials. 10 | 11 | 1. License. 12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn 13 | members during their LinkedIn Learning subscription a non-exclusive, 14 | non-transferable copyright license, for internal use only, to 1) make a 15 | reasonable number of copies of the Licensed Materials, and 2) make 16 | derivative works of the Licensed Materials for the sole purpose of 17 | practicing skills taught in LinkedIn Learning courses. 18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject 19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members 20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable 21 | copyright license to distribute the Licensed Materials, except the 22 | Licensed Materials may not be included in any product or service (or 23 | otherwise used) to instruct or educate others. 24 | 25 | 2. Restrictions and Intellectual Property. 26 | - a. You may not to use, modify, copy, make derivative works of, publish, 27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the 28 | Licensed Materials, except as expressly set forth above in Section 1. 29 | - b. Linkedin (and its licensors) retains its intellectual property rights 30 | in the Licensed Materials. Except as expressly set forth in Section 1, 31 | LinkedIn grants no licenses. 32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any 33 | alleged infringement or misappropriation of any intellectual property rights 34 | of any third party based on modifications you make to the Licensed Materials, 35 | ii) any claims arising from your use or distribution of all or part of the 36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold 37 | harmless, and indemnify LinkedIn and its affiliates (and our and their 38 | respective employees, shareholders, and directors) from any claim or action 39 | brought by a third party, including all damages, liabilities, costs and 40 | expenses, including reasonable attorneys’ fees, to the extent resulting from, 41 | alleged to have resulted from, or in connection with: (a) your breach of your 42 | obligations herein; or (b) your use or distribution of any Licensed Materials. 43 | 44 | 3. Open source. This code may include open source software, which may be 45 | subject to other license terms as provided in the files. 46 | 47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS” 48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY, 49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY 50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR 51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR 52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS 53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING 54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A 55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT. 56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND 57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE 58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR 59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR 60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT 61 | EXPRESSLY STATED IN THESE TERMS. 62 | 63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT, 64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING 65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER 66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU 67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL: 68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT, 69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT 70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS 71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND 72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR 73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE 74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS. 75 | 76 | 6. Termination. This Agreement automatically terminates upon your breach of 77 | this Agreement or termination of your LinkedIn Learning subscription. On 78 | termination, all licenses granted under this Agreement will terminate 79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this 80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue 81 | the availability of some or all of the Licensed Materials at any time for any 82 | reason. 83 | 84 | 7. Miscellaneous. This Agreement will be governed by and construed in 85 | accordance with the laws of the State of California without regard to conflict 86 | of laws principles. The exclusive forum for any disputes arising out of or 87 | relating to this Agreement shall be an appropriate federal or state court 88 | sitting in the County of Santa Clara, State of California. If LinkedIn does 89 | not act to enforce a breach of this Agreement, that does not mean that 90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does 91 | not create a partnership, agency relationship, or joint venture between the 92 | parties. Neither party has the power or authority to bind the other or to 93 | create any obligation or responsibility on behalf of the other. You may not, 94 | without LinkedIn’s prior written consent, assign or delegate any rights or 95 | obligations under these terms, including in connection with a change of 96 | control. Any purported assignment and delegation shall be ineffective. The 97 | Agreement shall bind and inure to the benefit of the parties, their respective 98 | successors and permitted assigns. If any provision of the Agreement is 99 | unenforceable, that provision will be modified to render it enforceable to the 100 | extent possible to give effect to the parties’ intentions and the remaining 101 | provisions will not be affected. This Agreement is the only agreement between 102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior 103 | agreements relating to the Licensed Materials. 104 | 105 | Last Updated: March 2019 106 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2022 LinkedIn Corporation 2 | All Rights Reserved. 3 | 4 | Licensed under the LinkedIn Learning Exercise File License (the "License"). 5 | See LICENSE in the project root for license information. 6 | 7 | Please note, this project may automatically load third party code from external 8 | repositories (for example, NPM modules, Composer packages, or other dependencies). 9 | If so, such third party code may be subject to other license terms than as set 10 | forth above. In addition, such third party code may also depend on and load 11 | multiple tiers of dependencies. Please review the applicable licenses of the 12 | additional dependencies. 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Desafío de programación: Java 2 | Este es el repositorio del curso de LinkedIn Learning `[Desafío de programación: Java]`. El curso completo está disponible en [LinkedIn Learning][lil-course-url]. 3 | 4 | ![COURSENAME][lil-thumbnail-url] 5 | 6 | Consulta el archivo Readme en la rama main para obtener instrucciones e información actualizadas. 7 | 8 | Refuerza tus conocimientos de programación en Java y mejorar tu pensamiento lógico-computacional a través de la solución de ejercicios prácticos que te supondrán un verdadero reto y te permitirá refrescar tus conocimientos. Durante el contenido se te planteará resolver una serie de minidesafíos de programación, y por cada reto y se te dará posteriormente la solución óptima. Los problemas que se se muestran son los típicos que podrías encontrar en tu práctica diaria, para que te sean útiles, y van desde un nivel iniciación-básico a alguno más avanzado. 9 | 10 | ## Instrucciones 11 | 12 | Este curso está integrado con GitHub Codespaces, un entorno de desarrollo instantáneo alojado en la nube que ofrece toda la funcionalidad de tu IDE favorito sin tener que configurar una máquina local. Con Codespaces puedes practicar en cualquier lugar y desde cualquier dispositivo, de modo que no necesitas instalar ninguna otra herramienta. 13 | Cada episodio de la serie Level Up ofrece al menos 12 ejercicios prácticos en diferentes niveles de dificultad para que puedas desafiarte y reforzar lo que has aprendido. Aprende a configurar y utilizar un espacio de código con el vídeo “Cómo usar GitHub Codespaces con este curso”. 14 | 15 | Este repositorio tiene una única rama (branch) para todos los vídeos del curso. 16 | 17 | ## Ramas 18 | Las ramas están estructuradas para corresponder a los vídeos del curso. La convención de nomenclatura es Capítulo#_Vídeo#. Por ejemplo, la rama denominada `02_03` corresponde al segundo capítulo y al tercer vídeo de ese capítulo. Algunas ramas tendrán un estado inicial y otro final. Están marcadas con las letras i («inicio») y f («fin»). La branch i tiene el mismo código que al principio del vídeo. La branch f tiene el mismo código que al final del vídeo. La rama master tiene el estado final del código que aparece en el curso. 19 | 20 | ### Docente 21 | 22 | **Mariona Nadal** 23 | 24 | Echa un vistazo a mis otros cursos en [LinkedIn Learning](https://www.linkedin.com/learning/instructors/mariona-nadal). 25 | 26 | [0]: # (Replace these placeholder URLs with actual course URLs) 27 | [lil-course-url]: https://www.linkedin.com/learning/desafio-de-programacion-java 28 | [lil-thumbnail-url]: https://media.licdn.com/dms/image/C4D0DAQH2tEpDQ5GX6Q/learning-public-crop_675_1200/0/1668096644384?e=2147483647&v=beta&t=hopWc_U4D5D1qKrsHpe3vQH-s0jwjMGkm6ysMxjpSSo 29 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_01/GeneradorBoletoSimple.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_01; 2 | 3 | import java.util.Arrays; 4 | 5 | public class GeneradorBoletoSimple { 6 | 7 | private static final int MIN = 1; 8 | private static final int MAX = 50; 9 | private static final int NUMS = 5; 10 | 11 | public static int[] generaBoleto() { 12 | int[] numeros = new int[NUMS]; 13 | for (int i = 0; i < NUMS; i ++) { 14 | numeros[i] = generaNumero(); 15 | } 16 | Arrays.sort(numeros); 17 | return numeros; 18 | } 19 | 20 | private static int generaNumero() { 21 | return (int) (Math.random() * (MAX - MIN + 1)) + MIN; 22 | } 23 | 24 | public static void main(String[] args) { 25 | for (int i = 0; i < 100; i++) { 26 | int[] boleto = generaBoleto(); 27 | System.out.println(Arrays.toString(boleto)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_01/GeneradorBoletoSimple2.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_01; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class GeneradorBoletoSimple2 { 8 | 9 | private static final int MIN = 1; 10 | private static final int MAX = 50; 11 | private static final int NUMS = 5; 12 | 13 | public static List generaBoleto() { 14 | List numeros = new ArrayList<>(); 15 | for (int i = 0; i < NUMS; i++) { 16 | int num = generaNumero(); 17 | while (numeros.contains(num)) { 18 | num = generaNumero(); 19 | } 20 | numeros.add(num); 21 | } 22 | Collections.sort(numeros); 23 | return numeros; 24 | } 25 | 26 | private static int generaNumero() { 27 | return (int) (Math.random() * (MAX - MIN + 1)) + MIN; 28 | } 29 | 30 | public static void main(String[] args) { 31 | for (int i = 0; i < 100; i++) { 32 | List boleto = generaBoleto(); 33 | System.out.println(boleto); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_02/Boleto.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_02; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | public class Boleto { 9 | 10 | public static final int MIN_N = 1; 11 | public static final int MAX_N = 50; 12 | public static final int NUMS = 6; 13 | public static final int MIN_R = 1; 14 | public static final int MAX_R = 10; 15 | 16 | private int reintegro; 17 | private int[] numeros; 18 | 19 | public Boleto() { 20 | numeros = generaBoleto(MIN_N, MAX_N, NUMS); 21 | reintegro = generaNumero(MIN_R, MAX_R); 22 | } 23 | 24 | private static int[] generaBoleto(int min, int max, int nums) { 25 | List boleto = new ArrayList<>(); 26 | 27 | for (int i = 0; i < nums; i++) { 28 | int num = generaNumero(min, max); 29 | while (boleto.contains(num)) { 30 | num = generaNumero(min, max); 31 | } 32 | boleto.add(num); 33 | } 34 | Collections.sort(boleto); 35 | return boleto.stream().mapToInt(Integer::intValue).toArray(); 36 | } 37 | 38 | private static int generaNumero(int min, int max) { 39 | return (int) (Math.random() * (max - min + 1)) + min; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "N: " + Arrays.toString(numeros) + " R: " + reintegro; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_02/GeneradorBoletoReintegro.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_02; 2 | 3 | public class GeneradorBoletoReintegro { 4 | 5 | public static void main(String[] args) { 6 | for (int i = 0; i < 100; i++) { 7 | Boleto boleto = new Boleto(); 8 | System.out.println(boleto); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_03/ColumnaBingo.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_03; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | public class ColumnaBingo { 9 | private LetraBingo letra; 10 | private int[] nums; 11 | 12 | public ColumnaBingo(LetraBingo letra) { 13 | this.letra = letra; 14 | this.nums = generaColumna(letra); 15 | } 16 | 17 | private int[] generaColumna(LetraBingo letra) { 18 | List numeros = new ArrayList<>(); 19 | 20 | for (int i = 0; i < letra.getLon(); i ++) { 21 | int num = generaNumero(letra.getMin(), letra.getMax()); 22 | while (numeros.contains(num)) { 23 | num = generaNumero(letra.getMin(), letra.getMax()); 24 | } 25 | numeros.add(num); 26 | } 27 | Collections.sort(numeros); 28 | return numeros.stream().mapToInt(Integer::intValue).toArray(); 29 | } 30 | 31 | private static int generaNumero(int min, int max) { 32 | return (int) (Math.random() * (max - min + 1)) + min; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return letra.getLetra() + ": " + Arrays.toString(nums); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_03/GeneradorTableroBingo.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_03; 2 | 3 | public class GeneradorTableroBingo { 4 | public static void main(String[] args) { 5 | TableroBingo tablero = new TableroBingo(); 6 | System.out.println(tablero); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_03/LetraBingo.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_03; 2 | 3 | public enum LetraBingo { 4 | B(1, 15, 5), I(16, 30, 5), N(31, 45, 4), G(46, 60, 5), O(61, 75, 5); 5 | 6 | private int min; 7 | private int max; 8 | private int lon; 9 | 10 | LetraBingo(int min, int max, int lon) { 11 | this.min = min; 12 | this.max = max; 13 | this.lon = lon; 14 | } 15 | 16 | public String getLetra() { 17 | return this.name(); 18 | } 19 | 20 | public int getMin() { 21 | return min; 22 | } 23 | 24 | public int getMax() { 25 | return max; 26 | } 27 | 28 | public int getLon() { 29 | return lon; 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_03/TableroBingo.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_03; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class TableroBingo { 7 | private List columnas = new ArrayList<>(); 8 | 9 | public TableroBingo() { 10 | for (LetraBingo letra : LetraBingo.values()) { 11 | columnas.add(new ColumnaBingo(letra)); 12 | } 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | String s = ""; 18 | for (ColumnaBingo columnaBingo : columnas) { 19 | s += columnaBingo.toString() + "\n"; 20 | } 21 | return s; 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_04/SorteoNavidad.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_04; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Comparator; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Random; 9 | 10 | public class SorteoNavidad { 11 | private static final int MIN_NUM = 0; 12 | private static final int MAX_NUM = 99999; 13 | private static final int DIG = 14 | (int) Math.floor(Math.log10(MAX_NUM) + 1); 15 | 16 | private static final Random R = new Random(); 17 | 18 | private List bomboNumeros = new ArrayList<>(); 19 | private List bomboPremios = new ArrayList<>(); 20 | private Map tablaPremios = new HashMap<>(); 21 | 22 | public SorteoNavidad() { 23 | for (int i = MIN_NUM; i <= MAX_NUM; i++) { 24 | bomboNumeros.add(i); 25 | } 26 | for (TipoPremio premio : TipoPremio.values()) { 27 | for (int i = 0; i < premio.getNumPremios(); i ++) { 28 | bomboPremios.add(premio); 29 | } 30 | } 31 | } 32 | 33 | public void sorteo() { 34 | while (!bomboPremios.isEmpty()) { 35 | int premioAlea = R.nextInt(bomboPremios.size()); 36 | TipoPremio premio = bomboPremios.remove(premioAlea); 37 | int numAlea = R.nextInt(bomboNumeros.size()); 38 | int num = bomboNumeros.remove(numAlea); 39 | tablaPremios.put(num, premio); 40 | } 41 | } 42 | 43 | public void printTablaPorNum() { 44 | System.out.println("Tabla ordenada por número"); 45 | if (tablaPremios.isEmpty()) { 46 | System.err.println("Sorteo pendiente"); 47 | } 48 | tablaPremios.keySet().stream().sorted().forEach( 49 | k -> System.out.println(formateaLinea(k, tablaPremios.get(k))) 50 | ); 51 | } 52 | 53 | public void printTablaPorPremio() { 54 | System.out.println("Tabla ordenada por premios"); 55 | if (tablaPremios.isEmpty()) { 56 | System.err.println("Sorteo pendiente"); 57 | } 58 | tablaPremios.entrySet().stream().sorted( 59 | new Comparator>() { 60 | public int compare(Map.Entry o1, 61 | Map.Entry o2) { 62 | return o1.getValue().compareTo(o2.getValue()); 63 | } 64 | } 65 | ).forEach( 66 | e -> System.out.println(formateaLinea(e)) 67 | ); 68 | } 69 | 70 | private String formateaLinea(Integer num, TipoPremio premio) { 71 | return String.format("%0" + DIG + "d", num) + ": " 72 | + premio.getPremioPorEuro() + "€"; 73 | } 74 | 75 | private String formateaLinea(Map.Entry entry) { 76 | return formateaLinea(entry.getKey(), entry.getValue()); 77 | } 78 | 79 | public static void main(String[] args) { 80 | SorteoNavidad sorteo = new SorteoNavidad(); 81 | sorteo.sorteo(); 82 | sorteo.printTablaPorNum(); 83 | System.out.println("================"); 84 | sorteo.printTablaPorPremio(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_04/TipoPremio.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_04; 2 | 3 | public enum TipoPremio { 4 | GORDO (20000, 1), 5 | SEGUNDO (6250, 1), 6 | TERCERO (2500, 1), 7 | CUARTO (1000, 2), 8 | QUINTO (300, 8), 9 | PEDREA (5, 18);// 1794); 10 | 11 | private int premioPorEuro; 12 | private int numPremios; 13 | 14 | TipoPremio(int premioPorEuro, int numPremios) { 15 | this.premioPorEuro = premioPorEuro; 16 | this.numPremios = numPremios; 17 | } 18 | 19 | public int getPremioPorEuro() { 20 | return premioPorEuro; 21 | } 22 | 23 | public int getNumPremios() { 24 | return numPremios; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_05/ValidadorBoletoSimple.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_05; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | public class ValidadorBoletoSimple { 9 | 10 | public static int validarBoleto(int[] boleto, int[] sorteo) { 11 | int aciertos = 0; 12 | // convertimos el array a lista para poder usar el contains 13 | List listaSorteo = new ArrayList(); 14 | Collections.addAll(listaSorteo, 15 | Arrays.stream(sorteo).boxed().toArray(Integer[]::new)); 16 | 17 | for (int nB : boleto) { 18 | if (listaSorteo.contains(nB)) { 19 | aciertos++; 20 | } 21 | } 22 | 23 | return aciertos; 24 | } 25 | 26 | public static int validarBoletoSinConversion(int[] boleto, 27 | int[] sorteo) { 28 | int aciertos = 0; 29 | int i = 0; 30 | 31 | for (int nB : boleto) { 32 | // suponemos que ambas listas están ordenadas 33 | while (i < sorteo.length && nB > sorteo[i]) { 34 | i++; 35 | } 36 | if (i < sorteo.length && nB == sorteo[i]) { 37 | aciertos++; 38 | } 39 | } 40 | 41 | return aciertos; 42 | } 43 | 44 | public static void main(String[] args) { 45 | int[] boleto = {7, 12, 25, 36, 38}; 46 | int[] sorteo = {16, 27, 36, 38, 43}; 47 | System.out.println(validarBoleto(boleto, sorteo)); 48 | System.out.println(validarBoletoSinConversion(boleto, sorteo)); 49 | 50 | int[] boleto2 = {7, 12, 25, 36, 38}; 51 | int[] sorteo2 = {16, 27, 37, 39, 43}; 52 | System.out.println(validarBoleto(boleto2, sorteo2)); 53 | System.out.println(validarBoletoSinConversion(boleto2, sorteo2)); 54 | 55 | int[] boleto3 = {7, 12, 25, 36, 38}; 56 | int[] sorteo3 = {7, 12, 25, 36, 38}; 57 | System.out.println(validarBoleto(boleto3, sorteo3)); 58 | System.out.println(validarBoletoSinConversion(boleto3, sorteo3)); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_06/Boleto.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_06; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | public class Boleto { 9 | 10 | public static final int MIN_N = 1; 11 | public static final int MAX_N = 50; 12 | public static final int NUMS = 6; 13 | public static final int MIN_R = 1; 14 | public static final int MAX_R = 10; 15 | 16 | private int reintegro; 17 | private int[] numeros; 18 | 19 | public Boleto() { 20 | numeros = generaBoleto(MIN_N, MAX_N, NUMS); 21 | reintegro = generaNumero(MIN_R, MAX_R); 22 | } 23 | 24 | private static int[] generaBoleto(int min, int max, int nums) { 25 | List boleto = new ArrayList<>(); 26 | 27 | for (int i = 0; i < nums; i ++) { 28 | int num = generaNumero(min, max); 29 | while (boleto.contains(num)) { 30 | num = generaNumero(min, max); 31 | } 32 | boleto.add(num); 33 | } 34 | Collections.sort(boleto); 35 | // (7) Convertimos la lista de Integer a array de int 36 | return boleto.stream().mapToInt(Integer::intValue).toArray(); 37 | } 38 | 39 | private static int generaNumero(int min, int max) { 40 | // (3) Generamos un número aleatorio entre MIN y MAX (ambos incluídos) 41 | return (int) (Math.random() * (max - min + 1)) + min; 42 | } 43 | 44 | public Premio validar(Boleto sorteo) { 45 | int aciertos = aciertos(sorteo); 46 | boolean reintegro = reintegro(sorteo); 47 | Premio premio = switch (aciertos) { 48 | case NUMS -> reintegro ? Premio.PLENO : Premio.SEIS_SIN; 49 | case NUMS - 1 -> reintegro ? Premio.CINCO_CON : Premio.CINCO_SIN; 50 | case NUMS - 2 -> reintegro ? Premio.CUATRO_CON : Premio.CUATRO_SIN; 51 | case NUMS - 3 -> reintegro ? Premio.TRES_CON : Premio.TRES_SIN; 52 | default -> reintegro ? Premio.REINTEGRO : Premio.NADA; 53 | }; 54 | return premio; 55 | } 56 | 57 | private boolean reintegro(Boleto sorteo) { 58 | return this.reintegro == sorteo.reintegro; 59 | } 60 | 61 | private int aciertos(Boleto sorteo) { 62 | int aciertos = 0; 63 | int i = 0; 64 | 65 | for (int nB : numeros) { 66 | // suponemos que ambas listas están ordenadas 67 | while (i < sorteo.numeros.length && nB > sorteo.numeros[i]) { 68 | i++; 69 | } 70 | if (i < sorteo.numeros.length && nB == sorteo.numeros[i]) { 71 | aciertos ++; 72 | } 73 | } 74 | 75 | return aciertos; 76 | } 77 | 78 | @Override 79 | public String toString() { 80 | return "N: " + Arrays.toString(numeros) + " R: " + reintegro; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_06/Premio.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_06; 2 | 3 | public enum Premio { 4 | PLENO, 5 | SEIS_SIN, 6 | CINCO_CON, 7 | CINCO_SIN, 8 | CUATRO_CON, 9 | CUATRO_SIN, 10 | TRES_CON, 11 | TRES_SIN, 12 | REINTEGRO, 13 | NADA 14 | } 15 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_06/ValidadorBoletoReintegro.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_06; 2 | 3 | public class ValidadorBoletoReintegro { 4 | 5 | public static void main(String[] args) { 6 | Boleto sorteo = new Boleto(); 7 | System.out.println("Sorteo: " + sorteo); 8 | for (int i = 0; i < 10000; i++) { 9 | Boleto apuesta = new Boleto(); 10 | Premio premio = apuesta.validar(sorteo); 11 | if (premio != Premio.NADA && premio != Premio.REINTEGRO) { 12 | System.out.println("Premio para " + apuesta + ": " + premio); 13 | } 14 | } 15 | Premio pleno = sorteo.validar(sorteo); 16 | System.out.println("Premio para " + sorteo + ": " + pleno); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_07/SorteoBingo.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_07; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Random; 6 | 7 | public class SorteoBingo { 8 | private static final int MIN = 1; 9 | private static final int MAX = 75; 10 | private static final int CADENCIA = 3000; // ms 11 | private static final Random R = new Random(); 12 | 13 | private List bolas = new ArrayList<>(); 14 | 15 | public SorteoBingo() { 16 | for (int i = MIN; i <= MAX; i++) { 17 | bolas.add(i); 18 | } 19 | } 20 | 21 | public void sortear() { 22 | try { 23 | while (!bolas.isEmpty()) { 24 | int bola = extraerBola(); 25 | System.out.print(bola + " "); 26 | Thread.sleep(CADENCIA); 27 | } 28 | } catch (InterruptedException e) { 29 | System.out.println("\n¡BINGO!"); 30 | } 31 | } 32 | 33 | private int extraerBola() { 34 | int pos = R.nextInt(bolas.size()); 35 | return bolas.remove(pos); 36 | } 37 | 38 | public static void main(String[] args) { 39 | SorteoBingo sorteo = new SorteoBingo(); 40 | sorteo.sortear(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_08/FormateadorFechas.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_08; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.Scanner; 6 | 7 | public class FormateadorFechas { 8 | 9 | public static void main(String[] args) { 10 | try (Scanner s = new Scanner(System.in)) { 11 | System.out.println("Indica el formato de fecha deseado: "); 12 | String patron = s.nextLine(); 13 | try { 14 | SimpleDateFormat sdf = new SimpleDateFormat(patron); 15 | String ahora = sdf.format(new Date()); 16 | System.out.println("Fecha actual: " + ahora); 17 | } catch (IllegalArgumentException iae) { 18 | System.err.println(String.format( 19 | "El patrón indicado '%s' no es válido.", patron)); 20 | } 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_09/EdadExacta.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_09; 2 | 3 | import java.time.LocalDate; 4 | import java.time.Period; 5 | import java.time.format.DateTimeFormatter; 6 | import java.time.format.DateTimeParseException; 7 | import java.util.Scanner; 8 | 9 | public class EdadExacta { 10 | 11 | private static final String PATRON = "dd/MM/yyyy"; 12 | 13 | public static void main(String[] args) { 14 | try (Scanner s = new Scanner(System.in)) { 15 | System.out.println( 16 | "Indica tu fecha de nacimiento (" + PATRON + ")"); 17 | String fechaLeida = s.nextLine(); 18 | try { 19 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern(PATRON); 20 | LocalDate fecha = LocalDate.parse(fechaLeida, dtf); 21 | LocalDate ahora = LocalDate.now(); 22 | Period edad = Period.between(fecha, ahora); 23 | System.out.println( 24 | String.format("Edad: %d años, %d meses y %d días", 25 | edad.getYears(), edad.getMonths(), edad.getDays())); 26 | if (edad.getMonths() == 0) { 27 | if (edad.getDays() == 0) { 28 | System.out.println( 29 | "¡FELICIDADES! ¡Hoy es tu cumpleaños!"); 30 | } else { 31 | System.out.println( 32 | "¡Felicidades! Tu cumpleaños ha sido hace poco..."); 33 | } 34 | } else if (edad.getMonths() == 11) { 35 | System.out.println( 36 | "¡Felicidades! Tu cumpleaños se acerca..."); 37 | } 38 | } catch (DateTimeParseException e) { 39 | System.err.println(String.format( 40 | "La fecha indicada ('%s') " 41 | + "no sigue el patrón esperado ('%s').", 42 | fechaLeida, PATRON)); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_10/ContadorLetras.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_10; 2 | 3 | import java.util.Map; 4 | import java.util.TreeMap; 5 | 6 | public class ContadorLetras { 7 | 8 | public static void main(String[] args) { 9 | if (args.length == 0) { 10 | System.err.println("Necesito al menos un argumento de entrada."); 11 | return; 12 | } 13 | String texto = args[0]; 14 | Map contador = new TreeMap<>(); 15 | for (char l : texto.toCharArray()) { 16 | Integer cont = contador.get(l); 17 | if (cont == null) { 18 | cont = 0; 19 | } 20 | contador.put(l, ++cont); 21 | } 22 | System.out.println(contador); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_11/RellenarMatriz.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_11; 2 | 3 | public class RellenarMatriz { 4 | 5 | public static void main(String[] args) { 6 | try { 7 | int x = Integer.valueOf(args[0]); 8 | int y = Integer.valueOf(args[1]); 9 | int[][] matriz = new int[x][y]; 10 | for (int i = 0; i < x; i++) { 11 | for (int j = 0; j < y; j++) { 12 | matriz[i][j] = i*i + j; // la fórmula que queramos 13 | } 14 | } 15 | pintarMatriz(matriz); 16 | } catch (IndexOutOfBoundsException | NumberFormatException e) { 17 | System.err.println( 18 | "Necesito al menos dos argumentos, numéricos, de entrada."); 19 | } 20 | } 21 | 22 | private static void pintarMatriz(int[][] matriz) { 23 | for (int i = 0; i < matriz.length; i++) { 24 | for (int j = 0; j < matriz[i].length; j++) { 25 | System.out.print(matriz[i][j] + " "); 26 | } 27 | System.out.println(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_12/SumarMatrices.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_12; 2 | 3 | public class SumarMatrices { 4 | 5 | public static int[][] sumar(int[][] m1, int[][] m2) { 6 | if (m1.length != m2.length || m1[0].length != m2[0].length) { 7 | throw new IllegalArgumentException( 8 | "Las dos matrices a sumar deben tener las mismas dimensiones"); 9 | } 10 | int[][] suma = new int[m1.length][m1[0].length]; 11 | for (int i = 0; i < m1.length; i ++) { 12 | for (int j = 0; j < m1[0].length; j++) { 13 | suma[i][j] = m1[i][j] + m2[i][j]; 14 | } 15 | } 16 | return suma; 17 | } 18 | 19 | public static void main(String[] args) { 20 | int[][] matriz1 = {{1, 2, 3}, {4, 5, 6}}; 21 | int[][] matriz2 = {{10, 20, 30}, {40, 50, 60}}; 22 | pintarMatriz(sumar(matriz1, matriz2)); 23 | } 24 | 25 | private static void pintarMatriz(int[][] matriz) { 26 | for (int i = 0; i < matriz.length; i++) { 27 | for (int j = 0; j < matriz[i].length; j++) { 28 | System.out.print(matriz[i][j] + " "); 29 | } 30 | System.out.println(); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_13/MultiplicarMatrices.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_13; 2 | 3 | public class MultiplicarMatrices { 4 | 5 | public static int[][] multiplicar(int[][] m1, int[][] m2) { 6 | int filas1 = m1.length; 7 | int cols1 = m1[0].length; 8 | int filas2 = m2.length; 9 | int cols2 = m2[0].length; 10 | 11 | if (cols1 != filas2) { 12 | throw new IllegalArgumentException( 13 | "El número de columnas de la primera matriz " 14 | + "debe coincidir con el número de filas de la segunda"); 15 | } 16 | int[][] producto = new int[filas1][cols2]; 17 | for (int i = 0; i < filas1; i ++) { 18 | for (int j = 0; j < cols2; j++) { 19 | int prod = 0; 20 | for (int k = 0; k < cols1; k++) { 21 | prod += m1[i][k] * m2[k][j]; 22 | } 23 | producto[i][j] = prod; 24 | } 25 | } 26 | return producto; 27 | } 28 | 29 | public static void main(String[] args) { 30 | int[][] matriz1 = {{1, 2, 3}, {4, 5, 6}}; 31 | int[][] matriz2 = {{7, 8}, {9, 10}, {11, 12}}; 32 | pintarMatriz(multiplicar(matriz1, matriz2)); 33 | } 34 | 35 | private static void pintarMatriz(int[][] matriz) { 36 | for (int i = 0; i < matriz.length; i++) { 37 | for (int j = 0; j < matriz[i].length; j++) { 38 | System.out.print(matriz[i][j] + " "); 39 | } 40 | System.out.println(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_14/CalcularMinimo.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_14; 2 | 3 | public class CalcularMinimo { 4 | 5 | public static int minimo(int[] lista) { 6 | int min = Integer.MAX_VALUE; 7 | for (int i = 0; i < lista.length; i++) { 8 | if (lista[i] < min) { 9 | min = lista[i]; 10 | } 11 | } 12 | return min; 13 | } 14 | 15 | public static void main(String[] args) { 16 | int[] lista = {9, 3, 2, 7, 8}; 17 | System.out.println(minimo(lista)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_15/CalcularMedia.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_15; 2 | 3 | import java.util.Arrays; 4 | import java.util.OptionalDouble; 5 | 6 | public class CalcularMedia { 7 | 8 | public static int media(int[] lista) { 9 | int media = 0; 10 | for (int i = 0; i < lista.length; i++) { 11 | media += lista[i]; 12 | } 13 | return media / lista.length; 14 | } 15 | 16 | public static double mediaDouble(int[] lista) { 17 | double media = 0; 18 | for (int i = 0; i < lista.length; i++) { 19 | media += lista[i]; 20 | } 21 | return media / lista.length; 22 | } 23 | 24 | public static double mediaStreams(int[] array) { 25 | OptionalDouble media = Arrays.stream(array).average(); 26 | if (media.isPresent()) { 27 | return media.getAsDouble(); 28 | } 29 | throw new IllegalStateException( 30 | "Error no esperado, no hay media"); 31 | } 32 | 33 | public static void main(String[] args) { 34 | int[] lista = {9, 3, 2, 7, 8}; 35 | System.out.println(media(lista)); 36 | System.out.println(mediaDouble(lista)); 37 | System.out.println(mediaStreams(lista)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_16/BuscarSinOrden.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_16; 2 | 3 | public class BuscarSinOrden { 4 | 5 | public static boolean buscar(int[] lista, int valor) { 6 | for (int n : lista) { 7 | if (n == valor) { 8 | return true; 9 | } 10 | } 11 | return false; 12 | } 13 | 14 | public static boolean buscarWhile(int[] lista, int valor) { 15 | boolean encontrado = false; 16 | int i = 0; 17 | while (!encontrado && i < lista.length) { 18 | encontrado = lista[i] == valor; 19 | i++; 20 | } 21 | return encontrado; 22 | } 23 | 24 | public static void main(String[] args) { 25 | int[] lista = {9, 3, 2, 7, 8}; 26 | System.out.println(buscar(lista, 7)); 27 | System.out.println(buscarWhile(lista, 7)); 28 | System.out.println(buscar(lista, 1)); 29 | System.out.println(buscarWhile(lista, 1)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_17/BuscarConOrden.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_17; 2 | 3 | import java.util.Arrays; 4 | 5 | public class BuscarConOrden { 6 | 7 | public static boolean busquedaBinaria(int[] lista, int elem) { 8 | return busquedaBinariaAux(lista, elem, 0, lista.length-1); 9 | } 10 | 11 | private static boolean busquedaBinariaAux( 12 | int[] lista, int elem, int ini, int fin) { 13 | int centro = Math.floorDiv(fin - ini, 2) + ini; 14 | int valorCentral = lista[centro]; 15 | if (valorCentral == elem) { 16 | return true; 17 | } 18 | if (fin - ini <= 1) { 19 | return false; 20 | } 21 | if (elem > valorCentral) { 22 | return busquedaBinariaAux(lista, elem, centro, fin); 23 | } 24 | // if (elem < valorCentral) { 25 | return busquedaBinariaAux(lista, elem, ini, centro); 26 | // } 27 | } 28 | 29 | public static void main(String[] args) { 30 | int[] lista = {9, 3, 2, 7, 8}; 31 | Arrays.sort(lista); 32 | System.out.println(busquedaBinaria(lista, 7)); 33 | System.out.println(busquedaBinaria(lista, 1)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_18/EsHoraDePlanchar.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_18; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public class EsHoraDePlanchar { 6 | 7 | public static Tarifa esHoraDePlanchar(LocalDateTime momento) { 8 | return switch(momento.getDayOfWeek()) { 9 | case SATURDAY, SUNDAY -> Tarifa.VALLE; 10 | default -> tarifaSegunHora(momento); 11 | }; 12 | } 13 | 14 | private static Tarifa tarifaSegunHora(LocalDateTime momento) { 15 | int hora = momento.getHour(); 16 | if (hora < 8) { 17 | return Tarifa.VALLE; 18 | } else if ((hora >= 10 && hora < 14) || 19 | (hora >= 18 && hora < 22)) { 20 | return Tarifa.PUNTA; 21 | } else { 22 | return Tarifa.LLANO; 23 | } 24 | } 25 | 26 | public static void main(String[] args) { 27 | LocalDateTime ahora = LocalDateTime.now(); 28 | System.out.println(esHoraDePlanchar(ahora)); 29 | 30 | for (int i = 0; i < 24; i ++) { 31 | System.out.println(i + "h: " 32 | + esHoraDePlanchar(LocalDateTime.now().withHour(i))); 33 | } 34 | for (int i = 0; i < 7; i ++) { 35 | LocalDateTime dia = LocalDateTime.now().minusDays(i); 36 | System.out.println(dia.getDayOfWeek() + ": " 37 | + esHoraDePlanchar(dia)); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/es/dsrroma/school/java/desafio1/video01_18/Tarifa.java: -------------------------------------------------------------------------------- 1 | package es.dsrroma.school.java.desafio1.video01_18; 2 | 3 | public enum Tarifa { 4 | VALLE, LLANO, PUNTA 5 | } 6 | --------------------------------------------------------------------------------