├── .gitignore ├── Apuntes curso básico de java.pdf ├── Ejercicios └── Ejercicios01.pdf ├── README.md ├── Soluciones ├── CloneWarsOO │ ├── .gitignore │ ├── .gradle │ │ ├── 7.1 │ │ │ ├── dependencies-accessors │ │ │ │ ├── dependencies-accessors.lock │ │ │ │ └── gc.properties │ │ │ ├── executionHistory │ │ │ │ ├── executionHistory.bin │ │ │ │ └── executionHistory.lock │ │ │ ├── fileChanges │ │ │ │ └── last-build.bin │ │ │ ├── fileHashes │ │ │ │ ├── fileHashes.bin │ │ │ │ └── fileHashes.lock │ │ │ └── gc.properties │ │ ├── buildOutputCleanup │ │ │ ├── buildOutputCleanup.lock │ │ │ ├── cache.properties │ │ │ └── outputFiles.bin │ │ ├── checksums │ │ │ └── checksums.lock │ │ └── vcs-1 │ │ │ └── gc.properties │ ├── .idea │ │ ├── .gitignore │ │ ├── artifacts │ │ │ └── CloneWarsOO_jar.xml │ │ ├── compiler.xml │ │ ├── gradle.xml │ │ ├── jarRepositories.xml │ │ ├── misc.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ └── main │ │ └── java │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ ├── Main.java │ │ └── model │ │ ├── Cuadricula.java │ │ ├── Droide.java │ │ └── TipoDroide.java ├── MoscaMatrizOO │ ├── .gitignore │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ ├── MoscaVector.iml │ └── src │ │ └── mosca │ │ ├── JuegoMosca.java │ │ ├── Mosca.java │ │ └── Tablero.java └── Unidad04-Varios │ ├── .idea │ ├── .gitignore │ ├── description.html │ ├── encodings.xml │ ├── misc.xml │ ├── modules.xml │ └── project-template.xml │ ├── Unidad04-Varios.iml │ └── src │ └── es │ └── joseluisg │ └── dam │ ├── Main.java │ ├── fraccion │ └── Relacional.java │ ├── ordenadores │ ├── Aula.java │ ├── Ordenador.java │ └── OrdenadorPro.java │ └── reloj │ └── Reloj.java ├── UD04.docx └── UD04.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | *.pptx 2 | .DS_Store 3 | /Ejercicios/*.docx 4 | upload.sh 5 | -------------------------------------------------------------------------------- /Apuntes curso básico de java.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Apuntes curso básico de java.pdf -------------------------------------------------------------------------------- /Ejercicios/Ejercicios01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Ejercicios/Ejercicios01.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programación - 04 Programación Orientada a Objetos 2 | 3 | Tema 04 Programación Orientada a Objetos. 1DAM. Curso 2021/2022. 4 | 5 | ![imagen](https://thesoftclix.com/wp-content/uploads/2019/09/unnamed-1.png) 6 | 7 | ## Contenidos 8 | 1. Programación Orientada a Objetos. 9 | 2. Objetos y Clases. 10 | 3. Clases. 11 | 4. Objetos. 12 | 5. Abstracción, Encapsulación y Ocultación. 13 | 6. this y null. 14 | 7. Constructores. 15 | 8. Métodos y Atributos de Clase. 16 | 9. Sobrecarga de Métodos. 17 | 18 | ## Recursos 19 | - Twitter: https://twitter.com/joseluisgonsan 20 | - GitHub: https://github.com/joseluisgs 21 | - Web: https://joseluisgs.github.io 22 | - Discord: https://discord.gg/uv7GcytM 23 | - Aula Virtual: https://aulavirtual33.educa.madrid.org/ies.luisvives.leganes/course/view.php?id=245 24 | 25 | 26 | 27 | ## Autor 28 | 29 | Codificado con :sparkling_heart: por [José Luis González Sánchez](https://twitter.com/joseluisgonsan) 30 | 31 | [![Twitter](https://img.shields.io/twitter/follow/joseluisgonsan?style=social)](https://twitter.com/joseluisgonsan) 32 | [![GitHub](https://img.shields.io/github/followers/joseluisgs?style=social)](https://github.com/joseluisgs) 33 | 34 | ### Contacto 35 |

36 | Cualquier cosa que necesites házmelo saber por si puedo ayudarte 💬. 37 |

38 |

39 | 40 | 42 |    43 | 44 | 46 |    47 | 48 | 50 |    51 | 52 | 54 | 55 |

56 | 57 | #### Agradecimientos: 58 | Mi más sincero agradecimiento a Fernando G. Aranzabe (CIFP Virgen de Gracia), porque estos contenidos no serían posible sin él, pues son la mayoría suyos y con el cual compartía y me unía (y me sigue uniendo) la misma visión en cómo enseñar la programación y qué elementos/contenidos usar en este proceso. Muchas gracias. -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gitignore: -------------------------------------------------------------------------------- 1 | /out 2 | /build -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/7.1/dependencies-accessors/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/7.1/dependencies-accessors/gc.properties -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/7.1/executionHistory/executionHistory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/7.1/executionHistory/executionHistory.bin -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/7.1/executionHistory/executionHistory.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/7.1/executionHistory/executionHistory.lock -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/7.1/fileChanges/last-build.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/7.1/fileHashes/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/7.1/fileHashes/fileHashes.bin -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/7.1/fileHashes/fileHashes.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/7.1/fileHashes/fileHashes.lock -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/7.1/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/7.1/gc.properties -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/buildOutputCleanup/buildOutputCleanup.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/buildOutputCleanup/buildOutputCleanup.lock -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/buildOutputCleanup/cache.properties: -------------------------------------------------------------------------------- 1 | #Thu Feb 03 10:36:05 CET 2022 2 | gradle.version=7.1 3 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/buildOutputCleanup/outputFiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/buildOutputCleanup/outputFiles.bin -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/checksums/checksums.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/checksums/checksums.lock -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.gradle/vcs-1/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/.gradle/vcs-1/gc.properties -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.idea/artifacts/CloneWarsOO_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/CloneWarsOO_jar 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 16 | 17 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | group 'es.joseluisgs' 6 | version '1.0-SNAPSHOT' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' 14 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' 15 | } 16 | 17 | test { 18 | useJUnitPlatform() 19 | } 20 | 21 | jar { 22 | manifest { 23 | attributes "Main-Class": "Main" 24 | } 25 | 26 | from { 27 | configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } 28 | } 29 | } -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/Soluciones/CloneWarsOO/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'CloneWarsOO' 2 | 3 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: Main 3 | 4 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import model.Cuadricula; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | // Compruebo numero de parámetros 6 | if (args.length != 6) { 7 | System.out.println("Usage: java -jar Programa -c -d -t"); 8 | } else 9 | try { 10 | int dimension = Integer.parseInt(args[1]); 11 | int droides = Integer.parseInt(args[3]); 12 | int tiempo = Integer.parseInt(args[5]); 13 | // Compruebo que los parámetros sean correctos 14 | if (checkParameters(dimension, droides, tiempo)) { 15 | // Creo Cuadricula 16 | Cuadricula cuadricula = new Cuadricula(dimension, droides, tiempo); 17 | cuadricula.init(); 18 | cuadricula.run(); 19 | cuadricula.report(); 20 | 21 | } else { 22 | System.out.println("Usage: java -jar Programa -c -d -t"); 23 | } 24 | 25 | } catch (NumberFormatException e) { 26 | System.out.println("Los parámetros deben ser enteros positivos"); 27 | System.out.println("Usage: java -jar Programa -c -d -t"); 28 | } 29 | } 30 | 31 | private static boolean checkParameters(int dimension, int droides, int tiempo) { 32 | boolean result = true; 33 | if (dimension < 5 || dimension > 9) { 34 | System.out.println("La dimension debe estar entre 5 y 9"); 35 | result = false; 36 | } 37 | if (droides < 5 || droides > 30) { 38 | System.out.println("El numero de droides debe estar entre 5 y 30"); 39 | result = false; 40 | } 41 | if (tiempo < 1 || tiempo > 3) { 42 | System.out.println("El tiempo de ejecución debe estar entre 1 y 3 minutos"); 43 | result = false; 44 | } 45 | return result; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/src/main/java/model/Cuadricula.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | public class Cuadricula { 4 | private final Droide[][] espacio; 5 | private final int dimension; 6 | private final int numDroides; 7 | private final int tiempoMax; 8 | private final int efectoDisparoNormal = 25; 9 | private final int efectoDisparoCritical = 50; 10 | private Droide[] droidesEnemigos; 11 | private int disparos; 12 | private int aciertos; 13 | 14 | 15 | public Cuadricula(int dimension, int numDroides, int tiempoMax) { 16 | this.dimension = dimension; 17 | this.numDroides = numDroides; 18 | this.tiempoMax = tiempoMax * 60 * 1000; // tiempo en milisegundos porque me lo dan en minutos 19 | espacio = new Droide[dimension][dimension]; 20 | } 21 | 22 | public void init() { 23 | System.out.println("Iniciando cuadricula..."); 24 | initDroidesEnemigos(); 25 | colocarDroidesEnemigos(); 26 | printEspacio(); 27 | } 28 | 29 | private void printEspacio() { 30 | for (int i = 0; i < dimension; i++) { 31 | for (int j = 0; j < dimension; j++) { 32 | if (espacio[i][j] != null) { 33 | System.out.print("[" + espacio[i][j].getModel() + "-" + espacio[i][j].getEnergia() + "]"); 34 | } else { 35 | System.out.print("[ ]"); 36 | } 37 | } 38 | System.out.println(); 39 | } 40 | } 41 | 42 | private void colocarDroidesEnemigos() { 43 | System.out.println("Colocando droides enemigos..."); 44 | limpiarEspacio(); 45 | for (int i = 0; i < droidesEnemigos.length; i++) { 46 | int fil; 47 | int col; 48 | // si esta vivo 49 | if (droidesEnemigos[i].isAlive()) { 50 | do { 51 | fil = (int) (Math.random() * dimension); 52 | col = (int) (Math.random() * dimension); 53 | } while (espacio[fil][col] != null); 54 | espacio[fil][col] = droidesEnemigos[i]; 55 | } 56 | } 57 | } 58 | 59 | private void limpiarEspacio() { 60 | for (int i = 0; i < dimension; i++) { 61 | for (int j = 0; j < dimension; j++) { 62 | espacio[i][j] = null; 63 | } 64 | } 65 | } 66 | 67 | private void initDroidesEnemigos() { 68 | droidesEnemigos = new Droide[numDroides]; 69 | for (int i = 0; i < numDroides; i++) { 70 | droidesEnemigos[i] = new Droide(); 71 | } 72 | } 73 | 74 | public void run() { 75 | System.out.println("Ejecutando cuadricula..."); 76 | int tiempo = 0; 77 | boolean salida = false; 78 | do { 79 | System.out.println("Tiempo: " + tiempo); 80 | System.out.println("escaneando y apuntando..."); 81 | // Obtengo la posicion a disparar 82 | int fil = (int) (Math.random() * dimension); 83 | int col = (int) (Math.random() * dimension); 84 | System.out.println("Disparando en: [" + fil + "][" + col + "]"); 85 | // Disparo 86 | disparos++; 87 | // Acierto si es != null 88 | if (espacio[fil][col] != null) { 89 | aciertos++; 90 | int efecto = getEfecto(); 91 | Droide d = espacio[fil][col]; 92 | d.setEnergia(d.getEnergia() - efecto); 93 | System.out.println("Has acertado con un daño de: " + efecto + " a: " + d); 94 | 95 | } else { 96 | System.out.println("Fallo"); 97 | } 98 | try { 99 | Thread.sleep(1000); 100 | } catch (InterruptedException e) { 101 | e.printStackTrace(); 102 | } 103 | tiempo += 1000; 104 | // Cambian de posicion los droides 105 | if (tiempo % 3000 == 0) { 106 | colocarDroidesEnemigos(); 107 | } 108 | // Imprimo el espacio 109 | printEspacio(); 110 | boolean finTiempo = tiempo >= tiempoMax; 111 | boolean todosMuertos = numDroides == droidesEnemigosMuertos(); 112 | salida = finTiempo || todosMuertos; 113 | } while (!salida); 114 | } 115 | 116 | private int getEfecto() { 117 | int efecto = (int) (Math.random() * 100); 118 | if (efecto <= 15) { 119 | return efectoDisparoCritical; 120 | } else { 121 | return efectoDisparoNormal; 122 | } 123 | } 124 | 125 | public void report() { 126 | System.out.println("Reporte de cuadricula..."); 127 | System.out.println("Droides enemigos: " + numDroides); 128 | System.out.println("Droides enemigos muertos: " + droidesEnemigosMuertos()); 129 | System.out.println("Droides enemigos vivos: " + (numDroides - droidesEnemigosMuertos())); 130 | System.out.println("Disparos realizados: " + disparos); 131 | System.out.println("Aciertos: " + aciertos); 132 | System.out.println("Procentaje de aciertos: " + procentajeAciertos() + "%"); 133 | System.out.println("Enemigos ordenados por energia: "); 134 | ordenarEnemigosPorEnergia(); 135 | imprimirEnemigos(); 136 | } 137 | 138 | private float procentajeAciertos() { 139 | float res = 0; 140 | if (disparos != 0) { 141 | res = (((float) aciertos) / disparos) * 100; 142 | return (float) Math.round(res * 100) / 100; 143 | } else { 144 | return 0; 145 | } 146 | } 147 | 148 | private void ordenarEnemigosPorEnergia() { 149 | for (int i = 0; i < droidesEnemigos.length; i++) { 150 | for (int j = i + 1; j < droidesEnemigos.length; j++) { 151 | if (droidesEnemigos[i].getEnergia() < droidesEnemigos[j].getEnergia()) { 152 | Droide aux = droidesEnemigos[i]; 153 | droidesEnemigos[i] = droidesEnemigos[j]; 154 | droidesEnemigos[j] = aux; 155 | } 156 | } 157 | } 158 | } 159 | 160 | private void imprimirEnemigos() { 161 | for (int i = 0; i < droidesEnemigos.length; i++) { 162 | System.out.println("[" + i + "] " + droidesEnemigos[i]); 163 | } 164 | } 165 | 166 | private int droidesEnemigosMuertos() { 167 | int muertos = 0; 168 | for (int i = 0; i < droidesEnemigos.length; i++) { 169 | if (!droidesEnemigos[i].isAlive()) { 170 | muertos++; 171 | } 172 | } 173 | return muertos; 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/src/main/java/model/Droide.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | public class Droide { 4 | private int energia; 5 | private TipoDroide model; 6 | 7 | public Droide() { 8 | randomDroide(); 9 | } 10 | 11 | private void randomDroide() { 12 | int random = (int) (Math.random() * 10); 13 | if (random < 3) { 14 | this.model = TipoDroide.SW447; 15 | this.energia = 50; 16 | } else if (random < 8) { 17 | this.model = TipoDroide.SW348; 18 | this.energia = 100; 19 | } else { 20 | this.model = TipoDroide.SW4421; 21 | this.energia = (int) (Math.random() * (150 - 100)) + 100; 22 | } 23 | } 24 | 25 | public int getEnergia() { 26 | return energia; 27 | } 28 | 29 | public void setEnergia(int energia) { 30 | this.energia = energia; 31 | if (this.energia < 0) { 32 | this.energia = 0; 33 | } 34 | } 35 | 36 | public boolean isAlive() { 37 | return this.energia != 0; 38 | } 39 | 40 | public TipoDroide getModel() { 41 | return model; 42 | } 43 | 44 | public void setModel(TipoDroide model) { 45 | this.model = model; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "Droide{" + 51 | "model=" + model + 52 | ", energia=" + energia + 53 | '}'; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Soluciones/CloneWarsOO/src/main/java/model/TipoDroide.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | public enum TipoDroide { 4 | SW348, SW447, SW4421 5 | } 6 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/MoscaVector.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/src/mosca/JuegoMosca.java: -------------------------------------------------------------------------------- 1 | package mosca; 2 | 3 | import java.util.Scanner; 4 | 5 | public class JuegoMosca { 6 | 7 | public static void main(String[] args) { 8 | System.out.println("La Mosca Vector"); 9 | int numIntentos = getNumIntentos(); 10 | // Pedir tamaño de Matriz 11 | int numCasillas = pedirNumeroCasillas(); 12 | // Crear Matriz 13 | Tablero tablero = new Tablero(numCasillas, numIntentos); 14 | 15 | tablero.init(); 16 | tablero.cazarMosca(); 17 | } 18 | 19 | 20 | private static int getNumIntentos() { 21 | Scanner sc = new Scanner(System.in); 22 | int intentos = 0; 23 | 24 | do { 25 | System.out.println("Introduce el número de intentos máximos, mayor a 1"); 26 | intentos = sc.nextInt(); 27 | } while (intentos < 1); 28 | 29 | return intentos; 30 | 31 | } 32 | 33 | private static int pedirNumeroCasillas() { 34 | Scanner sc = new Scanner(System.in); 35 | int numCasillas; 36 | do { 37 | System.out.println("Dime el número de casillas, siempre mayor a 5"); 38 | numCasillas = sc.nextInt(); 39 | System.out.println("Tamaño de vector es:" + numCasillas); 40 | } while (numCasillas < 5); 41 | return numCasillas; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/src/mosca/Mosca.java: -------------------------------------------------------------------------------- 1 | package mosca; 2 | 3 | public class Mosca { 4 | String nombre = "Soy una mosca cojonera"; 5 | 6 | public String getNombre() { 7 | return nombre; 8 | } 9 | 10 | public String toString() { 11 | return "Soy " + nombre + " y me gusta molestar"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Soluciones/MoscaMatrizOO/src/mosca/Tablero.java: -------------------------------------------------------------------------------- 1 | package mosca; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Tablero { 6 | private final Mosca MOSCA = new Mosca(); 7 | private int numIntentos = 5; 8 | private final Mosca[][] casillas; 9 | private int[] posMosca = {0, 0}; 10 | private boolean estaMuerta = false; 11 | 12 | public Tablero(int numCasillas, int numIntentos) { 13 | this.numIntentos = numIntentos; 14 | casillas = new Mosca[numCasillas][numCasillas]; 15 | } 16 | 17 | public void init() { 18 | iniciarCasillas(); 19 | situarMosca(); 20 | imprimirCasillas(); 21 | } 22 | 23 | public void iniciarCasillas() { 24 | for (int i = 0; i < casillas.length; i++) { 25 | for (int j = 0; j < casillas[i].length; j++) { 26 | casillas[i][j] = null; 27 | } 28 | } 29 | } 30 | 31 | public void situarMosca() { 32 | int fila = getPosicion(casillas); 33 | int columna = getPosicion(casillas); 34 | casillas[fila][columna] = MOSCA; 35 | } 36 | 37 | private int getPosicion(Mosca[][] casillas) { 38 | int fila; 39 | do { 40 | fila = (int) (Math.random() * casillas.length); 41 | //System.out.println(s + (fila + 1)); 42 | } while (fila < 0 || fila >= casillas.length); 43 | return fila; 44 | } 45 | 46 | public void imprimirCasillas() { 47 | //System.out.print("{ "); 48 | for (Mosca[] fila : casillas) { 49 | System.out.print("{ "); 50 | for (Mosca columna : fila) { 51 | if (columna == null) { 52 | System.out.print("[ ] "); 53 | } else { 54 | System.out.print("[X] "); 55 | } 56 | } 57 | System.out.println("} "); 58 | } 59 | //System.out.println("}"); 60 | } 61 | 62 | public int[] posicionGolpear() { 63 | Scanner sc = new Scanner(System.in); 64 | this.posMosca = new int[]{0, 0}; 65 | 66 | do { 67 | System.out.println("Introduce la posición de la Fila a atacar: "); 68 | posMosca[0] = sc.nextInt() - 1; 69 | System.out.println("La posición Fila elegida es: " + (posMosca[0] + 1)); 70 | } while (posMosca[0] < 0 || posMosca[0] >= casillas.length); 71 | 72 | do { 73 | System.out.println("Introduce la posición de la Columna a atacar: "); 74 | posMosca[1] = sc.nextInt() - 1; 75 | System.out.println("La posición Columna elegida es: " + (posMosca[1] + 1)); 76 | } while (posMosca[1] < 0 || posMosca[1] >= casillas.length); 77 | 78 | return (posMosca); 79 | } 80 | 81 | public boolean analizarGolpeo() { 82 | // Logica del juego 83 | // Acertamos 84 | if (casillas[posMosca[0]][posMosca[1]] == MOSCA) { 85 | estaMuerta = true; 86 | 87 | // Analizamos los limites 88 | } else { 89 | // Eje X horizontal 90 | boolean o = posMosca[0] != 0 && casillas[posMosca[0] - 1][posMosca[1]] == MOSCA; 91 | boolean e = posMosca[0] != casillas.length - 1 && casillas[posMosca[0] + 1][posMosca[1]] == MOSCA; 92 | // Eje Y vertical 93 | boolean n = posMosca[1] != 0 && casillas[posMosca[0]][posMosca[1] - 1] == MOSCA; 94 | boolean s = posMosca[1] != casillas.length - 1 && casillas[posMosca[0]][posMosca[1] + 1] == MOSCA; 95 | 96 | // Diagonal superior izquierda 97 | boolean no = posMosca[0] != 0 && posMosca[1] != 0 && casillas[posMosca[0] - 1][posMosca[1] - 1] == MOSCA; 98 | // Diagonal superior derecha 99 | boolean ne = posMosca[0] != 0 && posMosca[1] != casillas.length - 1 && casillas[posMosca[0] - 1][posMosca[1] + 1] == MOSCA; 100 | // Diagnal inferior izquierda 101 | boolean so = posMosca[0] != casillas.length - 1 && posMosca[1] != 0 && casillas[posMosca[0] + 1][posMosca[1] - 1] == MOSCA; 102 | // Diagnal inferior derecha 103 | boolean se = posMosca[0] != casillas.length - 1 && posMosca[1] != casillas.length - 1 && casillas[posMosca[0] + 1][posMosca[1] + 1] == MOSCA; 104 | 105 | if (o || e || n || s || no || ne || so || se) { 106 | // Revoloteamos 107 | System.out.println("¡CASI!"); 108 | iniciarCasillas(); 109 | situarMosca(); 110 | } 111 | } 112 | 113 | 114 | if (!estaMuerta) { 115 | System.out.println("¡Has fallado!"); 116 | } 117 | imprimirCasillas(); 118 | return estaMuerta; 119 | } 120 | 121 | public int[] getPosicion() { 122 | return posMosca; 123 | } 124 | 125 | public void cazarMosca() { 126 | do { 127 | // Pedirle la posición donde vas a dar un tortazo 128 | posicionGolpear(); 129 | 130 | // Anlizamos el Golpeo 131 | estaMuerta = analizarGolpeo(); 132 | numIntentos--; 133 | System.out.println("Te quedan " + numIntentos + " intentos"); 134 | } while (!estaMuerta && numIntentos > 0); 135 | 136 | if (estaMuerta) 137 | System.out.println("¡Has cazado a la maldita mosca!"); 138 | else 139 | System.out.println("¡Has perdido!"); 140 | 141 | System.out.println("Estaba en: {" 142 | + (getPosicion()[0] + 1) + ", " 143 | + (getPosicion()[1] + 1) + 144 | "}"); 145 | imprimirCasillas(); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/.idea/description.html: -------------------------------------------------------------------------------- 1 | Simple Java application that includes a class with main() method -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/.idea/project-template.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/Unidad04-Varios.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/src/es/joseluisg/dam/Main.java: -------------------------------------------------------------------------------- 1 | package es.joseluisg.dam; 2 | 3 | import es.joseluisg.dam.fraccion.Relacional; 4 | import es.joseluisg.dam.ordenadores.Aula; 5 | import es.joseluisg.dam.ordenadores.Ordenador; 6 | import es.joseluisg.dam.ordenadores.OrdenadorPro; 7 | import es.joseluisg.dam.reloj.Reloj; 8 | 9 | import java.util.Random; 10 | 11 | public class Main { 12 | 13 | public static void main(String[] args) { 14 | // write your code here 15 | System.out.println("Ejemplo Reloj"); 16 | Reloj r = new Reloj(22,30,27); 17 | System.out.println(r); 18 | System.out.println(r.getHora(true) + " Formato 24h"); 19 | System.out.println(r.getHora(false) + " Formato 12h"); 20 | r.recargarPila(); 21 | 22 | System.out.println("Ejemplo Relacional"); 23 | Relacional r1 = new Relacional(); 24 | r1.setNumerador(3); 25 | r1.setDenominador(4); 26 | System.out.println(r1); 27 | Relacional r2 = new Relacional(5,4); 28 | System.out.println(r2); 29 | System.out.println("SUMA"); 30 | System.out.println(r1.sumar(r2)); 31 | System.out.println(Relacional.sumar(r1,r2)); 32 | System.out.println("MULTIPLICACION"); 33 | System.out.println(r1.multiplicar(r2)); 34 | System.out.println(Relacional.multiplicar(r1,r2)); 35 | 36 | System.out.println("Ejemplo Ordenadores"); 37 | Aula a = Aula.getInstance("DAM", 1, 20); 38 | System.out.println(a); 39 | Ordenador o1 = new Ordenador("i7",8,500); 40 | Ordenador o2 = new Ordenador("i5",4,250); 41 | Ordenador o3 = new Ordenador("i7",8,750); 42 | Ordenador o4 = new Ordenador("i3",4,500); 43 | // Insertar 44 | a.insertarOrdenador(o1); 45 | a.insertarOrdenador(o2); 46 | a.insertarOrdenador(o3); 47 | a.insertarOrdenador(o4); 48 | // Mostrar todo 49 | a.mostrarOrdenadores(); 50 | // Buscar por id 51 | Ordenador b = a.buscarOrdenador(2); 52 | if (b != null) { 53 | System.out.println("Ordenador encontrado: " + b); 54 | } else { 55 | System.out.println("Ordenador no encontrado"); 56 | } 57 | // Actualizar por id 58 | o1.setProcesador("i5"); 59 | o1.setRam(16); 60 | a.actualizarOrdenador(o1); 61 | System.out.println("Ordenador Actualizado: " + o1); 62 | // Buscar por procesador 63 | a.buscarPorProcesador("i5"); 64 | // Eliminamos ordenador 65 | a.eliminarOrdenador(o4); 66 | // Mostrar todo 67 | System.out.println("Mostrar todo"); 68 | a.mostrarOrdenadores(); 69 | System.out.println("Ordenar por procesador"); 70 | a.ordenarPorProcesador(); 71 | a.mostrarOrdenadores(); 72 | System.out.println("Ordenar por Memoria"); 73 | a.ordenarPorMemoria(); 74 | a.mostrarOrdenadores(); 75 | 76 | a = Aula.getInstance("DAM2", 3, 200); 77 | System.out.println("Ordenar por Memoria"); 78 | a.ordenarPorMemoria(); 79 | a.mostrarOrdenadores(); 80 | 81 | Aula a1 = Aula.getInstance("DAM3", 14, 24); 82 | System.out.println("Ordenar por Memoria"); 83 | a1.ordenarPorMemoria(); 84 | a1.mostrarOrdenadores(); 85 | System.out.println("Ordenar con compareTo"); 86 | a1.ordenarOrdenadores(); 87 | a1.mostrarOrdenadores(); 88 | System.out.println("Interfaz fluida"); 89 | OrdenadorPro p1 = new OrdenadorPro(); 90 | p1.setProcesador("i7"); 91 | p1.setRam(16); 92 | p1.setBus("Pepe"); 93 | System.out.println(p1); 94 | OrdenadorPro p2 = new OrdenadorPro() 95 | .setProcesador("i5") 96 | .setRam(4) 97 | .setBus("Pepa"); 98 | System.out.println(p2); 99 | OrdenadorPro p3 = new OrdenadorPro() 100 | .procesador("i7") 101 | .ram(8) 102 | .bus("Pepa"); 103 | System.out.println(p3); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/src/es/joseluisg/dam/fraccion/Relacional.java: -------------------------------------------------------------------------------- 1 | package es.joseluisg.dam.fraccion; 2 | 3 | // http://www.sc.ehu.es/sbweb/fisica/cursoJava/fundamentos/estatico/fraccion/fraccion.htm 4 | 5 | public class Relacional { 6 | private int numerador; 7 | private int denominador; 8 | 9 | public Relacional() {} 10 | 11 | public Relacional(int numerador, int denominador) { 12 | this.numerador = numerador; 13 | this.denominador = denominador; 14 | } 15 | 16 | public int getNumerador() { 17 | return numerador; 18 | } 19 | 20 | public void setNumerador(int numerador) { 21 | this.numerador = numerador; 22 | } 23 | 24 | public int getDenominador() { 25 | return denominador; 26 | } 27 | 28 | public void setDenominador(int denominador) { 29 | this.denominador = denominador; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Relacional{" + 35 | "numerador=" + numerador + 36 | ", denominador=" + denominador + 37 | '}'; 38 | } 39 | 40 | public Relacional simplificar(Relacional r) { 41 | int dividir=mcd(); 42 | r.numerador /= dividir; 43 | r.denominador /= dividir; 44 | return this; 45 | } 46 | 47 | public Relacional sumar(Relacional r) { 48 | int num = numerador * r.denominador + r.numerador * denominador; 49 | int den = denominador * r.denominador; 50 | Relacional resultado = new Relacional(num, den); 51 | return resultado.simplificar(resultado); 52 | } 53 | 54 | public static Relacional sumar(Relacional r1, Relacional r2) { 55 | int num = r1.numerador * r2.denominador + r2.numerador * r1.denominador; 56 | int den = r1.denominador * r2.denominador; 57 | Relacional resultado = new Relacional(num, den); 58 | return resultado.simplificar(resultado); 59 | } 60 | 61 | public Relacional multiplicar(Relacional r) { 62 | int num = numerador * r.numerador; 63 | int den = denominador * r.denominador; 64 | Relacional resultado = new Relacional(num, den); 65 | return resultado.simplificar(resultado); 66 | } 67 | 68 | public static Relacional multiplicar(Relacional r1, Relacional r2) { 69 | int num = r1.numerador * r2.numerador; 70 | int den = r1.denominador * r2.denominador; 71 | Relacional resultado = new Relacional(num, den); 72 | return resultado.simplificar(resultado); 73 | } 74 | 75 | private int mcd(){ 76 | int u=Math.abs(numerador); 77 | int v=Math.abs(denominador); 78 | 79 | if(v==0){ 80 | return u; 81 | } 82 | int r; 83 | 84 | while(v!=0){ 85 | r=u%v; 86 | u=v; 87 | v=r; 88 | } 89 | return u; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/src/es/joseluisg/dam/ordenadores/Aula.java: -------------------------------------------------------------------------------- 1 | package es.joseluisg.dam.ordenadores; 2 | 3 | public class Aula { 4 | private static Aula instancia = null; 5 | 6 | private String nombre; 7 | private int numero; 8 | private int capacidad; 9 | private Ordenador[] ordenadores; 10 | 11 | public static Aula getInstance(String nombre, int numero, int capacidad) { 12 | if (instancia == null) { 13 | instancia = new Aula("Aula 1", 1, 20); 14 | } 15 | return instancia; 16 | } 17 | 18 | private Aula(String nombre, int numero, int capacidad) { 19 | this.nombre = nombre; 20 | this.numero = numero; 21 | this.capacidad = capacidad; 22 | this.ordenadores = new Ordenador[capacidad]; 23 | } 24 | 25 | public String getNombre() { 26 | return nombre; 27 | } 28 | 29 | public void setNombre(String nombre) { 30 | this.nombre = nombre; 31 | } 32 | 33 | public int getNumero() { 34 | return numero; 35 | } 36 | 37 | public void setNumero(int numero) { 38 | this.numero = numero; 39 | } 40 | 41 | public int getCapacidad() { 42 | return capacidad; 43 | } 44 | 45 | public void setCapacidad(int capacidad) { 46 | this.capacidad = capacidad; 47 | } 48 | 49 | public Ordenador[] getOrdenadores() { 50 | return ordenadores; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Aula{" + 56 | "nombre='" + nombre + '\'' + 57 | ", numero=" + numero + 58 | ", capacidad=" + capacidad + 59 | '}'; 60 | } 61 | 62 | public boolean insertarOrdenador(Ordenador ordenador) { 63 | for (int i = 0; i < ordenadores.length; i++) { 64 | if (ordenadores[i] == null) { 65 | ordenadores[i] = ordenador; 66 | return true; 67 | } 68 | } 69 | return false; 70 | } 71 | 72 | public void mostrarOrdenadores() { 73 | for (int i = 0; i < ordenadores.length; i++) { 74 | if (ordenadores[i] != null) { 75 | System.out.println(ordenadores[i]); 76 | } 77 | } 78 | } 79 | 80 | public Ordenador buscarOrdenador(int id) { 81 | for (Ordenador ordenador : ordenadores) { 82 | if (ordenador != null && ordenador.getId() == id) { 83 | return ordenador; 84 | } 85 | } 86 | return null; 87 | } 88 | 89 | public boolean actualizarOrdenador(Ordenador ordenador) { 90 | for (int i = 0; i < ordenadores.length; i++) { 91 | if (ordenadores[i] != null && ordenadores[i].getId() == ordenador.getId()) { 92 | ordenadores[i] = ordenador; 93 | return true; 94 | } 95 | } 96 | return false; 97 | } 98 | 99 | public void buscarPorProcesador(String procesador) { 100 | for (Ordenador ordenador : ordenadores) { 101 | if (ordenador != null && ordenador.getProcesador().equals(procesador)) { 102 | System.out.println(ordenador); 103 | } 104 | } 105 | } 106 | public boolean eliminarOrdenador(Ordenador ordenador) { 107 | for (int i = 0; i < ordenadores.length; i++) { 108 | if (ordenadores[i] != null && ordenadores[i].getId() == ordenador.getId()) { 109 | ordenadores[i] = null; 110 | return true; 111 | } 112 | } 113 | return false; 114 | } 115 | 116 | public void ordenarPorProcesador() { 117 | Ordenador aux; 118 | for (int i = 0; i < ordenadores.length; i++) { 119 | for (int j = i + 1; j < ordenadores.length; j++) { 120 | if (ordenadores[i] != null && ordenadores[j] != null && 121 | ordenadores[i].getProcesador().compareTo(ordenadores[j].getProcesador()) > 0) { 122 | aux = ordenadores[i]; 123 | ordenadores[i] = ordenadores[j]; 124 | ordenadores[j] = aux; 125 | } 126 | } 127 | } 128 | } 129 | 130 | public void ordenarPorMemoria() { 131 | Ordenador aux; 132 | for (int i = 0; i < ordenadores.length; i++) { 133 | for (int j = i + 1; j < ordenadores.length; j++) { 134 | if (ordenadores[i] != null && ordenadores[j] != null && 135 | ordenadores[i].getRam() > ordenadores[j].getRam()) { 136 | aux = ordenadores[i]; 137 | ordenadores[i] = ordenadores[j]; 138 | ordenadores[j] = aux; 139 | } 140 | } 141 | } 142 | } 143 | 144 | public void ordenarOrdenadores() { 145 | Ordenador aux; 146 | for (int i = 0; i < ordenadores.length; i++) { 147 | for (int j = i + 1; j < ordenadores.length; j++) { 148 | if (ordenadores[i] != null && ordenadores[j] != null && 149 | ordenadores[i].compareTo(ordenadores[j]) > 0) { 150 | aux = ordenadores[i]; 151 | ordenadores[i] = ordenadores[j]; 152 | ordenadores[j] = aux; 153 | } 154 | } 155 | } 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/src/es/joseluisg/dam/ordenadores/Ordenador.java: -------------------------------------------------------------------------------- 1 | package es.joseluisg.dam.ordenadores; 2 | 3 | public class Ordenador { 4 | private String procesador; 5 | private int ram; 6 | private int hd; 7 | private int id; 8 | private static int contadorID =1; 9 | 10 | public Ordenador() { 11 | this.id = contadorID ++; 12 | } 13 | 14 | public Ordenador(String procesador, int ram, int hd) { 15 | this.procesador = procesador; 16 | this.ram = ram; 17 | this.hd = hd; 18 | this.id = contadorID++; 19 | } 20 | 21 | public int getId() { 22 | return id; 23 | } 24 | 25 | public String getProcesador() { 26 | return procesador; 27 | } 28 | 29 | public void setProcesador(String procesador) { 30 | this.procesador = procesador; 31 | } 32 | 33 | public int getRam() { 34 | return ram; 35 | } 36 | 37 | public void setRam(int ram) { 38 | this.ram = ram; 39 | } 40 | 41 | public int getHd() { 42 | return hd; 43 | } 44 | 45 | public void setHd(int hd) { 46 | this.hd = hd; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "Ordenador{" + 52 | "procesador='" + procesador + '\'' + 53 | ", ram=" + ram + 54 | ", hd=" + hd + 55 | ", id=" + id + 56 | '}'; 57 | } 58 | 59 | public int compareTo(Ordenador o) { 60 | return this.getId() - o.getId(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/src/es/joseluisg/dam/ordenadores/OrdenadorPro.java: -------------------------------------------------------------------------------- 1 | package es.joseluisg.dam.ordenadores; 2 | 3 | import java.time.LocalDate; 4 | 5 | public class OrdenadorPro { 6 | private int id; 7 | private static int contadorID =1; 8 | 9 | private String procesador; 10 | private int ram; 11 | private int hd; 12 | private String grafica; 13 | private String bus; 14 | private String so; 15 | private String marca; 16 | private String modelo; 17 | private float precio; 18 | private LocalDate revision; 19 | private String mac; 20 | private String ip; 21 | 22 | public OrdenadorPro() { 23 | this.id = contadorID++; 24 | } 25 | public int getId() { 26 | return id; 27 | } 28 | 29 | public static int getContadorID() { 30 | return contadorID; 31 | } 32 | 33 | public String getProcesador() { 34 | return procesador; 35 | } 36 | 37 | public int getRam() { 38 | return ram; 39 | } 40 | 41 | public int getHd() { 42 | return hd; 43 | } 44 | 45 | public String getGrafica() { 46 | return grafica; 47 | } 48 | 49 | public String getBus() { 50 | return bus; 51 | } 52 | 53 | public String getSo() { 54 | return so; 55 | } 56 | 57 | public String getMarca() { 58 | return marca; 59 | } 60 | 61 | public String getModelo() { 62 | return modelo; 63 | } 64 | 65 | public float getPrecio() { 66 | return precio; 67 | } 68 | 69 | public LocalDate getRevision() { 70 | return revision; 71 | } 72 | 73 | public String getMac() { 74 | return mac; 75 | } 76 | 77 | public String getIp() { 78 | return ip; 79 | } 80 | 81 | public OrdenadorPro setProcesador(String procesador) { 82 | this.procesador = procesador; 83 | return this; 84 | } 85 | 86 | public OrdenadorPro setRam(int ram) { 87 | this.ram = ram; 88 | return this; 89 | } 90 | 91 | public OrdenadorPro setHd(int hd) { 92 | this.hd = hd; 93 | return this; 94 | } 95 | 96 | public OrdenadorPro setGrafica(String grafica) { 97 | this.grafica = grafica; 98 | return this; 99 | } 100 | 101 | public OrdenadorPro setBus(String bus) { 102 | this.bus = bus; 103 | return this; 104 | } 105 | 106 | public OrdenadorPro setSo(String so) { 107 | this.so = so; 108 | return this; 109 | } 110 | 111 | public OrdenadorPro setMarca(String marca) { 112 | this.marca = marca; 113 | return this; 114 | } 115 | 116 | public OrdenadorPro setModelo(String modelo) { 117 | this.modelo = modelo; 118 | return this; 119 | } 120 | 121 | public OrdenadorPro setPrecio(float precio) { 122 | this.precio = precio; 123 | return this; 124 | } 125 | 126 | public OrdenadorPro setRevision(LocalDate revision) { 127 | this.revision = revision; 128 | return this; 129 | } 130 | 131 | public OrdenadorPro setMac(String mac) { 132 | this.mac = mac; 133 | return this; 134 | } 135 | 136 | public OrdenadorPro setIp(String ip) { 137 | this.ip = ip; 138 | return this; 139 | } 140 | 141 | @Override 142 | public String toString() { 143 | return "OrdenadorPro{" + 144 | "id=" + id + 145 | ", procesador='" + procesador + '\'' + 146 | ", ram=" + ram + 147 | ", hd=" + hd + 148 | ", grafica='" + grafica + '\'' + 149 | ", bus='" + bus + '\'' + 150 | ", so='" + so + '\'' + 151 | ", marca='" + marca + '\'' + 152 | ", modelo='" + modelo + '\'' + 153 | ", precio=" + precio + 154 | ", revision=" + revision + 155 | ", mac='" + mac + '\'' + 156 | ", ip='" + ip + '\'' + 157 | '}'; 158 | } 159 | 160 | public OrdenadorPro procesador(String procesador) { 161 | this.procesador = procesador; 162 | return this; 163 | } 164 | 165 | 166 | 167 | public OrdenadorPro ram(int ram) { 168 | this.ram = ram; 169 | return this; 170 | } 171 | 172 | public OrdenadorPro hd(int hd) { 173 | this.hd = hd; 174 | return this; 175 | } 176 | 177 | public OrdenadorPro grafica(String grafica) { 178 | this.grafica = grafica; 179 | return this; 180 | } 181 | 182 | public OrdenadorPro bus(String bus) { 183 | this.bus = bus; 184 | return this; 185 | } 186 | 187 | public OrdenadorPro so(String so) { 188 | this.so = so; 189 | return this; 190 | } 191 | 192 | public OrdenadorPro marca(String marca) { 193 | this.marca = marca; 194 | return this; 195 | } 196 | 197 | public OrdenadorPro modelo(String modelo) { 198 | this.modelo = modelo; 199 | return this; 200 | } 201 | 202 | public OrdenadorPro precio(float precio) { 203 | this.precio = precio; 204 | return this; 205 | } 206 | 207 | public OrdenadorPro revision(LocalDate revision) { 208 | this.revision = revision; 209 | return this; 210 | } 211 | 212 | public OrdenadorPro mac(String mac) { 213 | this.mac = mac; 214 | return this; 215 | } 216 | 217 | public OrdenadorPro ip(String ip) { 218 | this.ip = ip; 219 | return this; 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /Soluciones/Unidad04-Varios/src/es/joseluisg/dam/reloj/Reloj.java: -------------------------------------------------------------------------------- 1 | package es.joseluisg.dam.reloj; 2 | 3 | public class Reloj { 4 | private int hora; 5 | private int minutos; 6 | private int segundos; 7 | 8 | public Reloj(int hora, int minutos, int segundos) { 9 | this.hora = hora; 10 | this.minutos = minutos; 11 | this.segundos = segundos; 12 | } 13 | 14 | public int getHora(boolean formato24) { 15 | return formato24 ? hora : hora % 12; 16 | } 17 | 18 | public void setHora(int hora24) { 19 | if (hora24 < 0 || hora24 > 23) { 20 | throw new IllegalArgumentException("Hora no válida"); 21 | } else { 22 | this.hora = hora24; 23 | } 24 | } 25 | 26 | public int getMinutos() { 27 | return minutos; 28 | } 29 | 30 | public void setMinutos(int minutos) { 31 | if (minutos < 0 || minutos > 59) { 32 | throw new IllegalArgumentException("Minutos no válidos"); 33 | } else { 34 | this.minutos = minutos; 35 | } 36 | } 37 | 38 | public int getSegundos() { 39 | return segundos; 40 | } 41 | 42 | public void setSegundos(int segundos) { 43 | if (minutos < 0 || minutos > 59) { 44 | throw new IllegalArgumentException("Segundos no válidos"); 45 | } else { 46 | this.segundos = segundos; 47 | } 48 | } 49 | 50 | public void recargarPila() { 51 | System.out.println("Recargando pila..."); 52 | System.out.println("Pila recargada"); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "Reloj{" + 58 | "hora=" + hora + 59 | ", minutos=" + minutos + 60 | ", segundos=" + segundos + 61 | '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /UD04.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/UD04.docx -------------------------------------------------------------------------------- /UD04.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisgs/Programacion-04-2021-2022/ed8d8d389a9413fe983758f11fe94f45cbb87449/UD04.pdf --------------------------------------------------------------------------------