mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-10 02:13:07 +01:00
Compare commits
48 Commits
2ecf781c77
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4200da990 | ||
|
|
3ec83f87d6 | ||
|
|
f66e4a5dc0 | ||
|
|
8d3b26bf60 | ||
|
|
3e859f9db9 | ||
|
|
5b3b41dba0 | ||
|
|
263bd4220b | ||
|
|
dc2cbeefbe | ||
|
|
b6b59798dc | ||
|
|
f0c090da0d | ||
|
|
abf5adcfe9 | ||
|
|
8e18fb286b | ||
|
|
fbcc8026ed | ||
|
|
9ec8ab1912 | ||
|
|
7dbbed7984 | ||
|
|
738c42f160 | ||
|
|
d8c4fa5e4b | ||
|
|
c054a8c34b | ||
|
|
037db3e9a8 | ||
|
|
ac7ecde4d4 | ||
|
|
4ce56eecb3 | ||
|
|
3f082aa864 | ||
|
|
8eba8ca7e3 | ||
|
|
1b2b2350f1 | ||
|
|
acb8877882 | ||
|
|
bc80b72094 | ||
|
|
1f7add9db3 | ||
|
|
2fbd405616 | ||
|
|
ed4fa3294a | ||
|
|
416b2d0e7a | ||
|
|
f62f0178ad | ||
|
|
366d9f0855 | ||
|
|
ec79e13264 | ||
|
|
61a60b9706 | ||
|
|
ef5b331c81 | ||
|
|
461b2dcf09 | ||
|
|
34c1985250 | ||
|
|
bdbffee001 | ||
|
|
6fcfc243a5 | ||
|
|
ccd2fc934d | ||
|
|
6d5b6d56d5 | ||
|
|
38fe9675d3 | ||
|
|
f8035afcb7 | ||
|
|
efa8fb3abc | ||
|
|
d52834bd8d | ||
|
|
d3bc19bf58 | ||
|
|
0e3d50092e | ||
|
|
dbeea11b71 |
15
.classpath
15
.classpath
@@ -6,5 +6,20 @@
|
|||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/Driver_MySQL_Connector_J/mysql-connector-java-8.0.19.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/jpa/javax.persistence_2.1.0.v201304241213.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/jpa/org.eclipse.persistence.jpa.modelgen_2.5.2.v20140319-9ad6abd.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/jpa/org.eclipse.persistence.jpars_2.5.2.v20140319-9ad6abd.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/com.sun.tools.xjc_2.2.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/com.sun.xml.bind_2.2.0.v201004141950.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/javax.activation_1.1.0.v201108011116.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/javax.mail_1.4.0.v201005080615.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/javax.xml.bind_2.2.0.v201105210648.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/javax.xml.stream_1.0.1.v201004272200.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/eclipselink.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/Jackson/jackson-annotations-2.9.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/Jackson/jackson-core-2.9.5.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/Jackson/jackson-databind-2.9.5.jar"/>
|
||||||
|
<classpathentry kind="lib" path="librerias/mongoDB-Java-driver/mongo-java-driver-3.12.12.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
141
BBDDs/01_BBDD_GestionVentaDeCoches/cochesConDatos.sql
Normal file
141
BBDDs/01_BBDD_GestionVentaDeCoches/cochesConDatos.sql
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,174 @@
|
|||||||
|
CREATE DATABASE IF NOT EXISTS `centroeducativo` /*!40100 DEFAULT CHARACTER SET utf8 */;
|
||||||
|
USE `centroeducativo`;
|
||||||
|
-- MySQL dump 10.13 Distrib 5.6.13, for Win32 (x86)
|
||||||
|
--
|
||||||
|
-- Host: 127.0.0.1 Database: centroeducativo
|
||||||
|
-- ------------------------------------------------------
|
||||||
|
-- Server version 5.6.16-log
|
||||||
|
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||||
|
/*!40101 SET NAMES utf8 */;
|
||||||
|
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||||
|
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||||
|
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||||
|
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||||
|
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||||
|
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `curso`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `curso`;
|
||||||
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
|
CREATE TABLE `curso` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`descripcion` varchar(45) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `curso`
|
||||||
|
--
|
||||||
|
|
||||||
|
LOCK TABLES `curso` WRITE;
|
||||||
|
/*!40000 ALTER TABLE `curso` DISABLE KEYS */;
|
||||||
|
INSERT INTO `curso` VALUES (1,'2017-18');
|
||||||
|
/*!40000 ALTER TABLE `curso` ENABLE KEYS */;
|
||||||
|
UNLOCK TABLES;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `estudiante`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `estudiante`;
|
||||||
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
|
CREATE TABLE `estudiante` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`nombre` varchar(150) DEFAULT NULL,
|
||||||
|
`apellido1` varchar(150) DEFAULT NULL,
|
||||||
|
`apellido2` varchar(150) DEFAULT NULL,
|
||||||
|
`dni` varchar(15) DEFAULT NULL,
|
||||||
|
`direccion` varchar(250) DEFAULT NULL,
|
||||||
|
`email` varchar(150) DEFAULT NULL,
|
||||||
|
`telefono` varchar(150) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `estudiante`
|
||||||
|
--
|
||||||
|
|
||||||
|
LOCK TABLES `estudiante` WRITE;
|
||||||
|
/*!40000 ALTER TABLE `estudiante` DISABLE KEYS */;
|
||||||
|
INSERT INTO `estudiante` VALUES (1,'Julio','Mármol','Mármol','14785236A','dir, 21','adsf','654785214'),(2,'Francisco','Fernández','Fernández','52874369B','dir, 24','f@f.com','741258963'),(3,'Miguel','Palacios','Fernández','58963214C','dir, 26','m@m.com','632521478');
|
||||||
|
/*!40000 ALTER TABLE `estudiante` ENABLE KEYS */;
|
||||||
|
UNLOCK TABLES;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `materia`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `materia`;
|
||||||
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
|
CREATE TABLE `materia` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`nombre` varchar(100) DEFAULT NULL,
|
||||||
|
`acronimo` varchar(15) DEFAULT NULL,
|
||||||
|
`curso_id` int(11) NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `fk_asignatura_curso1_idx` (`curso_id`),
|
||||||
|
CONSTRAINT `fk_asignatura_curso1` FOREIGN KEY (`curso_id`) REFERENCES `curso` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `materia`
|
||||||
|
--
|
||||||
|
|
||||||
|
LOCK TABLES `materia` WRITE;
|
||||||
|
/*!40000 ALTER TABLE `materia` DISABLE KEYS */;
|
||||||
|
INSERT INTO `materia` VALUES (1,'Programación','PROG',1),(2,'Lenguajes de Marcas y Sistemas de Gestión de la Información','LMSGI',1),(3,'Sistemas Informáticos','SI',1),(4,'Entornos de Desarrollo','EntDes',1),(5,'Bases de Datos','BD',1),(6,'Formación y Orientación Laboral','FOL',1);
|
||||||
|
/*!40000 ALTER TABLE `materia` ENABLE KEYS */;
|
||||||
|
UNLOCK TABLES;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `profesor`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `profesor`;
|
||||||
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
|
CREATE TABLE `profesor` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`nombre` varchar(150) DEFAULT NULL,
|
||||||
|
`apellido1` varchar(150) DEFAULT NULL,
|
||||||
|
`apellido2` varchar(150) DEFAULT NULL,
|
||||||
|
`dni` varchar(15) DEFAULT NULL,
|
||||||
|
`direccion` varchar(250) DEFAULT NULL,
|
||||||
|
`email` varchar(150) DEFAULT NULL,
|
||||||
|
`telefono` varchar(150) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `profesor`
|
||||||
|
--
|
||||||
|
|
||||||
|
LOCK TABLES `profesor` WRITE;
|
||||||
|
/*!40000 ALTER TABLE `profesor` DISABLE KEYS */;
|
||||||
|
INSERT INTO `profesor` VALUES (1,'Rafael Carlos','López','Ruiz','12345678b','Su casa, 34','asdf','sdaf'),(2,'Joaquín','Molinero','Suárez','23456789B','Su casa también, 42','joaquin@joaquin.com','654789322'),(3,'Miguel Ángel','Pérez','Carmona','98765432C','Otra casa, 12','miguel@miguel.com','654147852'),(4,'Alejandro','Fernández','Fernández','47125896D','Allí, 65','alejandro@alejandro.com','658974125'),(5,'Águeda','Cuenca','Cuenca','96325874','Graná, 25','','698521478');
|
||||||
|
/*!40000 ALTER TABLE `profesor` ENABLE KEYS */;
|
||||||
|
UNLOCK TABLES;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `valoracionmateria`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `valoracionmateria`;
|
||||||
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
|
CREATE TABLE `valoracionmateria` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`idProfesor` int(11) NOT NULL,
|
||||||
|
`idEstudiante` int(11) NOT NULL,
|
||||||
|
`idMateria` int(11) NOT NULL,
|
||||||
|
`valoracion` float DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `fk_asignatura_profesor_idx` (`idProfesor`),
|
||||||
|
KEY `fk_asignatura_estudiante1_idx` (`idEstudiante`),
|
||||||
|
KEY `fk_asignatura_asignatura1_idx` (`idMateria`),
|
||||||
|
CONSTRAINT `fk_asignatura_asignatura1` FOREIGN KEY (`idMateria`) REFERENCES `materia` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT `fk_asignatura_estudiante1` FOREIGN KEY (`idEstudiante`) REFERENCES `estudiante` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT `fk_asignatura_profesor` FOREIGN KEY (`idProfesor`) REFERENCES `profesor` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `valoracionmateria`
|
||||||
|
--
|
||||||
|
|
||||||
|
LOCK TABLES `valoracionmateria` WRITE;
|
||||||
|
/*!40000 ALTER TABLE `valoracionmateria` DISABLE KEYS */;
|
||||||
|
INSERT INTO `valoracionmateria` VALUES (1,1,1,1,6),(2,1,1,2,7),(3,2,1,3,6),(4,3,1,4,6),(5,4,1,5,8),(6,5,1,6,4),(7,1,2,1,5),(8,1,2,2,7),(9,2,2,3,8),(10,3,2,4,5),(11,4,2,5,6),(12,5,2,6,4);
|
||||||
|
/*!40000 ALTER TABLE `valoracionmateria` ENABLE KEYS */;
|
||||||
|
UNLOCK TABLES;
|
||||||
|
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||||
|
|
||||||
|
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||||
|
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||||
|
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||||
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
|
-- Dump completed on 2019-04-09 10:05:53
|
||||||
File diff suppressed because one or more lines are too long
BIN
BBDDs/03_BBDD_PoblacionEnProvincia/poblacionProvincial.mwb
Normal file
BIN
BBDDs/03_BBDD_PoblacionEnProvincia/poblacionProvincial.mwb
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
137
BBDDs/04_BBDD_Bankonter/bbdd-bankonter.sql
Normal file
137
BBDDs/04_BBDD_Bankonter/bbdd-bankonter.sql
Normal file
File diff suppressed because one or more lines are too long
41154
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/arbol.json
Normal file
41154
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/arbol.json
Normal file
File diff suppressed because it is too large
Load Diff
97
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/ccaa.json
Normal file
97
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/ccaa.json
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Andalucía",
|
||||||
|
"code": "01"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Aragón",
|
||||||
|
"code": "02"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Asturias, Principado de",
|
||||||
|
"code": "03"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Balears, Illes",
|
||||||
|
"code": "04"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Canarias",
|
||||||
|
"code": "05"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Cantabria",
|
||||||
|
"code": "06"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Castilla y León",
|
||||||
|
"code": "07"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Castilla - La Mancha",
|
||||||
|
"code": "08"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Cataluńa",
|
||||||
|
"code": "09"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Comunitat Valenciana",
|
||||||
|
"code": "10"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Extremadura",
|
||||||
|
"code": "11"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Galicia",
|
||||||
|
"code": "12"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Madrid, Comunidad de",
|
||||||
|
"code": "13"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Murcia, Región de",
|
||||||
|
"code": "14"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Navarra, Comunidad Foral de",
|
||||||
|
"code": "15"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "País Vasco",
|
||||||
|
"code": "16"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Rioja, La",
|
||||||
|
"code": "17"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Ceuta",
|
||||||
|
"code": "18"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "0",
|
||||||
|
"label": "Melilla",
|
||||||
|
"code": "19"
|
||||||
|
}
|
||||||
|
]
|
||||||
40657
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/poblaciones.json
Normal file
40657
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/poblaciones.json
Normal file
File diff suppressed because it is too large
Load Diff
262
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/provincias.json
Normal file
262
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/provincias.json
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"parent_code": "01",
|
||||||
|
"code": "04",
|
||||||
|
"label": "Almería"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "01",
|
||||||
|
"code": "11",
|
||||||
|
"label": "Cádiz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "01",
|
||||||
|
"code": "14",
|
||||||
|
"label": "Córdoba"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "01",
|
||||||
|
"code": "18",
|
||||||
|
"label": "Granada"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "01",
|
||||||
|
"code": "21",
|
||||||
|
"label": "Huelva"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "01",
|
||||||
|
"code": "23",
|
||||||
|
"label": "Jaén"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "01",
|
||||||
|
"code": "29",
|
||||||
|
"label": "Málaga"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "01",
|
||||||
|
"code": "41",
|
||||||
|
"label": "Sevilla"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "02",
|
||||||
|
"code": "22",
|
||||||
|
"label": "Huesca"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "02",
|
||||||
|
"code": "44",
|
||||||
|
"label": "Teruel"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "02",
|
||||||
|
"code": "50",
|
||||||
|
"label": "Zaragoza"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "03",
|
||||||
|
"code": "33",
|
||||||
|
"label": "Asturias"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "04",
|
||||||
|
"code": "07",
|
||||||
|
"label": "Balears, Illes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "05",
|
||||||
|
"code": "35",
|
||||||
|
"label": "Palmas, Las"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "05",
|
||||||
|
"code": "38",
|
||||||
|
"label": "Santa Cruz de Tenerife"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "06",
|
||||||
|
"code": "39",
|
||||||
|
"label": "Cantabria"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "05",
|
||||||
|
"label": "Ávila"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "09",
|
||||||
|
"label": "Burgos"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "24",
|
||||||
|
"label": "León"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "34",
|
||||||
|
"label": "Palencia"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "37",
|
||||||
|
"label": "Salamanca"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "40",
|
||||||
|
"label": "Segovia"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "42",
|
||||||
|
"label": "Soria"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "47",
|
||||||
|
"label": "Valladolid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "07",
|
||||||
|
"code": "49",
|
||||||
|
"label": "Zamora"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "08",
|
||||||
|
"code": "02",
|
||||||
|
"label": "Albacete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "08",
|
||||||
|
"code": "13",
|
||||||
|
"label": "Ciudad Real"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "08",
|
||||||
|
"code": "16",
|
||||||
|
"label": "Cuenca"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "08",
|
||||||
|
"code": "19",
|
||||||
|
"label": "Guadalajara"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "08",
|
||||||
|
"code": "45",
|
||||||
|
"label": "Toledo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "09",
|
||||||
|
"code": "08",
|
||||||
|
"label": "Barcelona"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "09",
|
||||||
|
"code": "17",
|
||||||
|
"label": "Girona"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "09",
|
||||||
|
"code": "25",
|
||||||
|
"label": "Lleida"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "09",
|
||||||
|
"code": "43",
|
||||||
|
"label": "Tarragona"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "10",
|
||||||
|
"code": "03",
|
||||||
|
"label": "Alicante/Alacant"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "10",
|
||||||
|
"code": "12",
|
||||||
|
"label": "Castellón/Castelló"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "10",
|
||||||
|
"code": "46",
|
||||||
|
"label": "Valencia/València"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "11",
|
||||||
|
"code": "06",
|
||||||
|
"label": "Badajoz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "11",
|
||||||
|
"code": "10",
|
||||||
|
"label": "Cáceres"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "12",
|
||||||
|
"code": "15",
|
||||||
|
"label": "Coruña, A"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "12",
|
||||||
|
"code": "27",
|
||||||
|
"label": "Lugo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "12",
|
||||||
|
"code": "32",
|
||||||
|
"label": "Ourense"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "12",
|
||||||
|
"code": "36",
|
||||||
|
"label": "Pontevedra"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "13",
|
||||||
|
"code": "28",
|
||||||
|
"label": "Madrid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "14",
|
||||||
|
"code": "30",
|
||||||
|
"label": "Murcia"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "15",
|
||||||
|
"code": "31",
|
||||||
|
"label": "Navarra"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "16",
|
||||||
|
"code": "01",
|
||||||
|
"label": "Araba/Álava"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "16",
|
||||||
|
"code": "48",
|
||||||
|
"label": "Bizkaia"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "16",
|
||||||
|
"code": "20",
|
||||||
|
"label": "Gipuzkoa"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "17",
|
||||||
|
"code": "26",
|
||||||
|
"label": "Rioja, La"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "18",
|
||||||
|
"code": "51",
|
||||||
|
"label": "Ceuta"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parent_code": "19",
|
||||||
|
"code": "52",
|
||||||
|
"label": "Melilla"
|
||||||
|
}
|
||||||
|
]
|
||||||
Binary file not shown.
80
BBDDs/05_MunicipiosYProvincias/municipiosYProvincias.sql
Normal file
80
BBDDs/05_MunicipiosYProvincias/municipiosYProvincias.sql
Normal file
File diff suppressed because one or more lines are too long
1071
BBDDs/06_JSON_West_World_La_serie/westworld-serie.json
Normal file
1071
BBDDs/06_JSON_West_World_La_serie/westworld-serie.json
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
BIN
librerias/EclipseLink2.5.2/jlib/eclipselink.jar
Normal file
BIN
librerias/EclipseLink2.5.2/jlib/eclipselink.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
librerias/EclipseLink2.5.2/jlib/moxy/com.sun.tools.xjc_2.2.0.jar
Normal file
BIN
librerias/EclipseLink2.5.2/jlib/moxy/com.sun.tools.xjc_2.2.0.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
librerias/JDBC_Oracle_Connection_Pool/ucp.jar
Normal file
BIN
librerias/JDBC_Oracle_Connection_Pool/ucp.jar
Normal file
Binary file not shown.
BIN
librerias/Jackson/jackson-annotations-2.9.0.jar
Normal file
BIN
librerias/Jackson/jackson-annotations-2.9.0.jar
Normal file
Binary file not shown.
BIN
librerias/Jackson/jackson-core-2.9.5.jar
Normal file
BIN
librerias/Jackson/jackson-core-2.9.5.jar
Normal file
Binary file not shown.
BIN
librerias/Jackson/jackson-databind-2.9.5.jar
Normal file
BIN
librerias/Jackson/jackson-databind-2.9.5.jar
Normal file
Binary file not shown.
BIN
librerias/mongoDB-Java-driver/mongo-java-driver-3.12.12.jar
Normal file
BIN
librerias/mongoDB-Java-driver/mongo-java-driver-3.12.12.jar
Normal file
Binary file not shown.
@@ -53,6 +53,30 @@ public class Utils {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pide un número entero al usuario
|
||||||
|
* @param mensaje String que va a mostrarse en consola para pedir el número
|
||||||
|
* @return Número entero introducido por el usuario
|
||||||
|
*/
|
||||||
|
public static float pideNumeroFloat (String mensaje) {
|
||||||
|
float n = 0;
|
||||||
|
boolean esNumeroCorrecto;
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
do {
|
||||||
|
esNumeroCorrecto = false;
|
||||||
|
try {
|
||||||
|
System.out.println(mensaje);
|
||||||
|
n = Float.parseFloat(sc.nextLine());
|
||||||
|
esNumeroCorrecto = true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("No ha introducido un número");
|
||||||
|
}
|
||||||
|
} while (esNumeroCorrecto == false);
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +114,41 @@ public class Utils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene un número entero a través de un objeto Scanner
|
||||||
|
* @return Número entero introducido por el usuario.
|
||||||
|
*/
|
||||||
|
public static double obtenerDoublePorScanner() {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
return sc.nextDouble();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Error, introduce un número double: ");
|
||||||
|
sc.nextLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene un número entero a través de un objeto Scanner
|
||||||
|
* @return Número entero introducido por el usuario.
|
||||||
|
*/
|
||||||
|
public static double obtenerDoublePorScanner(String mensaje) {
|
||||||
|
System.out.println(mensaje);
|
||||||
|
return obtenerDoublePorScanner();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene un número entero a través de un objeto Scanner
|
||||||
|
* @return Número entero introducido por el usuario.
|
||||||
|
*/
|
||||||
|
public static float obtenerFloatPorScanner(String mensaje) {
|
||||||
|
return (float) obtenerDoublePorScanner(mensaje);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtiene un número entero a través de un JOptionPane
|
* Obtiene un número entero a través de un JOptionPane
|
||||||
* @return Número entero introducido a través de un JOptionPane.
|
* @return Número entero introducido a través de un JOptionPane.
|
||||||
@@ -119,6 +178,11 @@ public class Utils {
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double obtenerDoubleConDescripcion(String desc) {
|
||||||
|
System.out.println(desc);
|
||||||
|
return obtenerDoublePorScanner();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return Número entero introducido por el usuario
|
* @return Número entero introducido por el usuario
|
||||||
|
|||||||
@@ -149,6 +149,19 @@ public class UtilsArrays {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param m
|
||||||
|
*/
|
||||||
|
public static void imprimeMatriz (char m[][]) {
|
||||||
|
for (int i = 0; i < m.length; i++) {
|
||||||
|
for (int j = 0; j < m[i].length; j++) {
|
||||||
|
System.out.print(m[i][j] + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void ordenaArray (int a[], boolean asc) {
|
public static void ordenaArray (int a[], boolean asc) {
|
||||||
boolean hayIntercambios;
|
boolean hayIntercambios;
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ public class Ejercicio04_EncontrarPalabraMasLarga {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
System.out.println("Palabra más larga: " +
|
System.out.println("Contar ocurrencias: " +
|
||||||
palabraMasLarga("rafa está afónico hoy"));
|
palabraMasLarga("rafa está afónico hoy"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package tutorialJava.capitulo4_Arrays.ejercicios.bloque06;
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque06;
|
||||||
|
|
||||||
import tutorialJava.UtilsArrays;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
public class Ej01_EjerciciosMatrices {
|
public class Ej01_EjerciciosMatrices {
|
||||||
|
|
||||||
@@ -19,20 +21,8 @@ public class Ej01_EjerciciosMatrices {
|
|||||||
imprimeMatriz(m);
|
imprimeMatriz(m);
|
||||||
System.out.println("Es positiva: " + esMatrizPositiva(m));
|
System.out.println("Es positiva: " + esMatrizPositiva(m));
|
||||||
System.out.println("Es diagonal: " + esMatrizDiagonal(m));
|
System.out.println("Es diagonal: " + esMatrizDiagonal(m));
|
||||||
System.out.println("Es triangular superior: " + esMatrizTriangularSuperior(m));
|
|
||||||
System.out.println("Es dispersa: " + esMatrizDispersa(m));
|
System.out.println("Es dispersa: " + esMatrizDispersa(m));
|
||||||
|
|
||||||
int array[] = arrayFromMatriz(m);
|
|
||||||
UtilsArrays.imprimeArray(array);
|
|
||||||
|
|
||||||
System.out.println("Es simétrica: " + esMatrizSimetrica(m));
|
|
||||||
|
|
||||||
int traspuesta[][] = dameMatrizTraspuesta(m);
|
|
||||||
imprimeMatriz(traspuesta);
|
|
||||||
|
|
||||||
matrizOpuesta(m);
|
|
||||||
imprimeMatriz(m);
|
|
||||||
|
|
||||||
int t[][] = eliminaFila(m, 2);
|
int t[][] = eliminaFila(m, 2);
|
||||||
imprimeMatriz(t);
|
imprimeMatriz(t);
|
||||||
}
|
}
|
||||||
@@ -218,7 +208,7 @@ public class Ej01_EjerciciosMatrices {
|
|||||||
* @param m
|
* @param m
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static void matrizOpuesta (int m[][]) {
|
public static void dameMatrizOpuesta (int m[][]) {
|
||||||
for (int i = 0; i < m.length; i++) {
|
for (int i = 0; i < m.length; i++) {
|
||||||
for (int j = 0; j < m[i].length; j++) {
|
for (int j = 0; j < m[i].length; j++) {
|
||||||
m[i][j] = -m[i][j];
|
m[i][j] = -m[i][j];
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque07_tresEnRaya;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class TresEnRaya {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int t[][] = new int[3][3];
|
||||||
|
// int t[][] = new int[][] {{2, 1, 1},
|
||||||
|
// {1, 2, 2},
|
||||||
|
// {2, 2, 0}};
|
||||||
|
int turno = 1;
|
||||||
|
inicializaTablero(t);
|
||||||
|
do {
|
||||||
|
// Muestro tablero
|
||||||
|
imprimieTablero(t);
|
||||||
|
// Pido jugada a jugador (turno)
|
||||||
|
pidoJugadaAJugador(t, turno);
|
||||||
|
// Cambiar turno
|
||||||
|
turno = cambiaTurno(turno);
|
||||||
|
} while (ganadorDelJuego(t) == 0 && !hayEmpate(t));
|
||||||
|
|
||||||
|
// Imprimo ganador o empate
|
||||||
|
int ganador = ganadorDelJuego(t);
|
||||||
|
if (ganador != 0) {
|
||||||
|
System.out.println("Ha ganado el jugador " + ganador);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Hay un empate");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param t
|
||||||
|
*/
|
||||||
|
public static void inicializaTablero(int t[][]) {
|
||||||
|
// Ponemos todos los valores a "0"
|
||||||
|
for (int i = 0; i < t.length; i++) {
|
||||||
|
for (int j = 0; j < t[i].length; j++) {
|
||||||
|
t[i][j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param t
|
||||||
|
*/
|
||||||
|
public static void imprimieTablero(int t[][]) {
|
||||||
|
System.out.println("\nTablero actual: ");
|
||||||
|
|
||||||
|
for (int i = 0; i < t.length; i++) {
|
||||||
|
for (int j = 0; j < t[i].length; j++) {
|
||||||
|
System.out.print( (t[i][j] != 0)? (t[i][j] == 1)? "X" : "O" : "-");
|
||||||
|
System.out.print("\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param t
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int ganadorDelJuego(int t[][]) {
|
||||||
|
// Compruebo cada fila
|
||||||
|
for (int i = 0; i < t.length; i++) {
|
||||||
|
if (t[i][0] == t[i][1] && t[i][1] == t[i][2]) {
|
||||||
|
return t[i][0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compruebo cada columna
|
||||||
|
for (int i = 0; i < t[0].length; i++) {
|
||||||
|
if (t[0][i] == t[1][i] && t[1][i] == t[2][i]) {
|
||||||
|
return t[0][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compruebo las diagonales
|
||||||
|
if (t[0][0] == t[1][1] && t[1][1] == t[2][2]) {
|
||||||
|
return t[0][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t[0][2] == t[1][1] && t[1][1] == t[2][0]) {
|
||||||
|
return t[0][2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// si llego hasta aquí, sé que el juego no se ha acabado.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean hayEmpate (int t[][]) {
|
||||||
|
for (int i = 0; i < t.length; i++) {
|
||||||
|
for (int j = 0; j < t[i].length; j++) {
|
||||||
|
if (t[i][j] == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param t
|
||||||
|
* @param jugador
|
||||||
|
*/
|
||||||
|
public static void pidoJugadaAJugador (int t[][], int jugador) {
|
||||||
|
int filaJugada = 0, columnaJugada = 0;
|
||||||
|
boolean casillaOcupada = false;
|
||||||
|
|
||||||
|
System.out.println("Turno del jugador: " + jugador);
|
||||||
|
|
||||||
|
do {
|
||||||
|
casillaOcupada = false;
|
||||||
|
filaJugada = Utils.obtenerEnteroEntreLimites("Introduzca la fila de su jugada: ", 0, 2);
|
||||||
|
columnaJugada = Utils.obtenerEnteroEntreLimites("Introduzca la columna de su jugada: ", 0, 2);
|
||||||
|
|
||||||
|
if (t[filaJugada][columnaJugada] != 0) {
|
||||||
|
System.out.println("La posición que ha pedido está ocupada, vuelva a intentarlo.");
|
||||||
|
casillaOcupada = true;
|
||||||
|
}
|
||||||
|
} while (casillaOcupada);
|
||||||
|
|
||||||
|
// Establezco la jugada del usuario
|
||||||
|
t[filaJugada][columnaJugada] = jugador;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param turno
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int cambiaTurno(int turno) {
|
||||||
|
return (turno % 2) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque08;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class Ej02_CiclicoEnArrayRespetandoIntervaloInterior {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int posIni, posFin;
|
||||||
|
int a[] = new int[10];
|
||||||
|
UtilsArrays.inicializaArray(a, 0, 9);
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
|
||||||
|
do {
|
||||||
|
posIni = Utils.obtenerEnteroEntreLimites("Introduzca posición Inicial: ", 0, 9);
|
||||||
|
posFin = Utils.obtenerEnteroEntreLimites("Introduzca posición Final: ", 0, 9);
|
||||||
|
if (posIni > posFin) {
|
||||||
|
System.out.println("Error. La posición inicial no puede ser mayor que "
|
||||||
|
+ " la posición final");
|
||||||
|
}
|
||||||
|
} while (posIni > posFin);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int aux = a[a.length - 1];
|
||||||
|
|
||||||
|
for (int i = a.length - 2; i > -1; i--) {
|
||||||
|
if (i < posIni || i > posFin) {
|
||||||
|
if (i == (posIni - 1)){
|
||||||
|
a[i + posFin - posIni + 2] = a[i];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a[i + 1] = a[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
a[0] = aux;
|
||||||
|
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque08;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Ej03_LetraDNI {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String letrasDNI = "TRWAGMYFPDXBNJZSQVHLCKE";
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int valorDni = 0;
|
||||||
|
|
||||||
|
boolean dniIntroducidoValido;
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
System.out.println("Introduzca su DNI sin letra: ");
|
||||||
|
String dniSinLetra = sc.nextLine();
|
||||||
|
valorDni = Integer.parseInt(dniSinLetra);
|
||||||
|
dniIntroducidoValido = true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.err.println("DNI introducido no es válido");
|
||||||
|
dniIntroducidoValido = false;
|
||||||
|
}
|
||||||
|
} while (!dniIntroducidoValido);
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
char letraDni = letrasDNI.charAt(valorDni % 23);
|
||||||
|
System.out.println("Letra DNI: " + letraDni);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque08;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class Ej04_MinYMaxEnMatriz {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
int m[][] = new int[6][10];
|
||||||
|
|
||||||
|
for (int i = 0; i < m.length; i++) {
|
||||||
|
for (int j = 0; j < m[i].length; j++) {
|
||||||
|
// Genero un número al azar que no existe en la matriz
|
||||||
|
int azar;
|
||||||
|
do {
|
||||||
|
azar = Utils.obtenerNumeroAzar(0, 1000);
|
||||||
|
} while (existeValorEnMatriz(m, azar));
|
||||||
|
|
||||||
|
// Aquí sé que el valor de 'azar' no se encuentra repetido
|
||||||
|
m[i][j] = azar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UtilsArrays.imprimeMatriz(m);
|
||||||
|
|
||||||
|
// Obtengo min y max
|
||||||
|
int filaMin = 0, filaMax = 0, colMin = 0, colMax = 0;
|
||||||
|
int min = m[0][0];
|
||||||
|
int max = m[0][0];
|
||||||
|
for (int i = 0; i < m.length; i++) {
|
||||||
|
for (int j = 0; j < m[i].length; j++) {
|
||||||
|
if (m[i][j] > max) {
|
||||||
|
max = m[i][j];
|
||||||
|
filaMax = i;
|
||||||
|
colMax = j;
|
||||||
|
}
|
||||||
|
if (m[i][j] < min) {
|
||||||
|
min = m[i][j];
|
||||||
|
filaMin = i;
|
||||||
|
colMin = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Máximo: " + max + "(" + filaMax + ", " + colMax +
|
||||||
|
") - Mínimo: " + min + "(" + filaMin + ", " + colMin + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param m
|
||||||
|
* @param valorBuscado
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean existeValorEnMatriz (int m[][], int valorBuscado) {
|
||||||
|
for (int i = 0; i < m.length; i++) {
|
||||||
|
for (int j = 0; j < m[i].length; j++) {
|
||||||
|
if (m[i][j] == valorBuscado) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque08;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class Ej06_PosiblesMovimientosAlfil {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int xAlfil, yAlfil;
|
||||||
|
int tablero[][] = UtilsArrays.creaEInicializaMatriz(8, 8, 0);
|
||||||
|
|
||||||
|
System.out.println("Tablero del ajedrez");
|
||||||
|
UtilsArrays.imprimeMatriz(tablero);
|
||||||
|
|
||||||
|
yAlfil = Utils.obtenerEnteroEntreLimites("Introduzca la fila del Alfil", 1, 8) - 1;
|
||||||
|
|
||||||
|
xAlfil = Utils.obtenerEnteroEntreLimites("Introduzca la columna del Alfil", 1, 8) - 1;
|
||||||
|
|
||||||
|
// Coloco el alfil en el tablero
|
||||||
|
tablero[yAlfil][xAlfil] = 2;
|
||||||
|
|
||||||
|
// Coloco valores en Diagonal principal sobre el alfil
|
||||||
|
for (int i = yAlfil - 1, j = xAlfil - 1; i > -1 && j > -1; i--, j--) {
|
||||||
|
tablero[i][j] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coloco valores en Diagonal principal bajo el alfil
|
||||||
|
for (int i = yAlfil + 1, j = xAlfil + 1; i < tablero.length && j < tablero[i].length ; i++, j++) {
|
||||||
|
tablero[i][j] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coloco valores en Diagonal secundaria sobre el alfil
|
||||||
|
for (int i = yAlfil - 1, j = xAlfil + 1; i > -1 && j < tablero[i].length ; i--, j++) {
|
||||||
|
tablero[i][j] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coloco valores en Diagonal secundaria bajo el alfil
|
||||||
|
for (int i = yAlfil + 1, j = xAlfil -1; i < tablero.length && j > -1 ; i++, j--) {
|
||||||
|
tablero[i][j] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
UtilsArrays.imprimeMatriz(tablero);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque08;
|
||||||
|
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class Ejercicio01_arrayImparesYPares {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a[] = new int[20];
|
||||||
|
|
||||||
|
UtilsArrays.inicializaArray(a, 0, 100);
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
|
||||||
|
ordenaParesEImpares(a);
|
||||||
|
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
*/
|
||||||
|
public static void ordenaParesEImpares (int a[]) {
|
||||||
|
|
||||||
|
while ( !(posicionUltimoPar(a) < posicionPrimerImpar(a))) {
|
||||||
|
int primeraPosImpar = posicionPrimerImpar(a);
|
||||||
|
int ultimaPosPar = posicionUltimoPar(a);
|
||||||
|
|
||||||
|
int aux = a[primeraPosImpar];
|
||||||
|
a[primeraPosImpar] = a[ultimaPosPar];
|
||||||
|
a[ultimaPosPar] = aux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int posicionUltimoPar (int a[]) {
|
||||||
|
int posicion = 0;
|
||||||
|
for (int i = 0; i < a.length; i++) {
|
||||||
|
if (a[i] % 2 == 0) {
|
||||||
|
posicion = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return posicion;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int posicionPrimerImpar (int a[]) {
|
||||||
|
for (int i = 0; i < a.length; i++) {
|
||||||
|
if (a[i] % 2 == 1) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque09;
|
||||||
|
|
||||||
|
public class Ejercicio01_StringFromArray {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a[] = new int[] {97, 98, 99, 100};
|
||||||
|
|
||||||
|
System.out.println("String devuelto: " + stringFromArray(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param b
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String stringFromArray (int b[]) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
|
for (int num : b) {
|
||||||
|
sb.append((char) num);
|
||||||
|
}
|
||||||
|
|
||||||
|
// for (int i = 0; i < b.length; i++) {
|
||||||
|
// sb.append((char) b[i]);
|
||||||
|
// }
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque09;
|
||||||
|
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class Ejercicio02_findAndReplace {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a[] = new int[] {97, 98, 99, 100};
|
||||||
|
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
findAndReplace(a, 99, 115);
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param b
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static void findAndReplace (int b[], int buscado, int reemplazo) {
|
||||||
|
|
||||||
|
for (int i = 0; i < b.length; i++) {
|
||||||
|
if (b[i] == buscado) {
|
||||||
|
b[i] = reemplazo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque09;
|
||||||
|
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class Ejercicio03_addInteger {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a[] = new int[] {97, 98, 99, 100};
|
||||||
|
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
UtilsArrays.imprimeArray(addInteger(a, 99));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param b
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int[] addInteger (int b[], int agregado) {
|
||||||
|
int c[] = new int[b.length + 1];
|
||||||
|
|
||||||
|
for (int i = 0; i < b.length; i++) {
|
||||||
|
c[i] = b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
c[c.length - 1] = agregado;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque09;
|
||||||
|
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class Ejercicio04_countOccurrences {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a[] = new int[] {97, 98, 99, 100, 99, 98};
|
||||||
|
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
System.out.println("Ocurrencias de 99: " + countOcurrences(a, 99));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param b
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int countOcurrences (int b[], int occurrence) {
|
||||||
|
int cont = 0;
|
||||||
|
|
||||||
|
for (int i : b) {
|
||||||
|
if (i == occurrence) cont++;
|
||||||
|
}
|
||||||
|
return cont;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque09;
|
||||||
|
|
||||||
|
import tutorialJava.UtilsArrays;
|
||||||
|
|
||||||
|
public class Ejercicio05_removeInteger {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a[] = new int[] {99, 98, 99, 100, 99, 98};
|
||||||
|
|
||||||
|
UtilsArrays.imprimeArray(a);
|
||||||
|
UtilsArrays.imprimeArray(removeInteger(a, 99));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param b
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int[] removeInteger (int b[], int forRemove) {
|
||||||
|
int contOccurrences =
|
||||||
|
Ejercicio04_countOccurrences.countOcurrences(b, forRemove);
|
||||||
|
int c[] = new int[b.length - contOccurrences];
|
||||||
|
|
||||||
|
int j = 0; // Sólo se utiliza en el nuevo array creado
|
||||||
|
for (int num : b) {
|
||||||
|
if (num != forRemove) {
|
||||||
|
c[j] = num;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque10;
|
||||||
|
|
||||||
|
public class Ejercicio01_LoteriaPrimitivaArrayConValoresSinRepeticion {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Declaración de variables
|
||||||
|
int apuesta[] = new int[7];
|
||||||
|
boolean numEncontradoEnPosicionesPrevias;
|
||||||
|
|
||||||
|
// Un bucle que recorre el array de izquiera a derecha
|
||||||
|
for (int i = 0; i < apuesta.length; i++) {
|
||||||
|
|
||||||
|
// No sé cuántas veces tendré que genera un número al azar para asegurarme
|
||||||
|
// de que no existe en los valores que se sitúan a la izquierda de la
|
||||||
|
// posición marcada por el valor de la "i".
|
||||||
|
do {
|
||||||
|
numEncontradoEnPosicionesPrevias = false;
|
||||||
|
apuesta[i] = (int) Math.round(Math.random() * (49 - 1) + 1);
|
||||||
|
|
||||||
|
// Busco el valor de la posición de "i" en las posiciones a la izquierda
|
||||||
|
// de ese valor
|
||||||
|
for (int j = 0; j < i; j++) {
|
||||||
|
if (apuesta[i] == apuesta[j]) {
|
||||||
|
numEncontradoEnPosicionesPrevias = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (numEncontradoEnPosicionesPrevias == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recorro y muestro el array
|
||||||
|
for (int i = 0; i < apuesta.length; i++) {
|
||||||
|
System.out.print(apuesta[i] + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque10;
|
||||||
|
|
||||||
|
public class Ejercicio02_OndaDeAsteriscosAlAzar {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Declaración de variables
|
||||||
|
char matriz[][] = new char[10][30];
|
||||||
|
int asteriscosEnCadaLinea;
|
||||||
|
|
||||||
|
// Relleno toda la matriz de espacios en blanco
|
||||||
|
for (int i = 0; i < matriz.length; i++) {
|
||||||
|
for (int j = 0; j < matriz[i].length; j++) {
|
||||||
|
matriz[i][j] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recorro todas las filas
|
||||||
|
for (int i = 0; i < matriz.length; i++) {
|
||||||
|
// Determina la cantidad de asteriscos a introducir en cada línea
|
||||||
|
asteriscosEnCadaLinea = (int) Math.round(Math.random() * 30);
|
||||||
|
|
||||||
|
// Llenar tantos asteriscos desde la izquierda como indique la variable
|
||||||
|
for (int j = 0; j < asteriscosEnCadaLinea; j++) {
|
||||||
|
matriz[i][j] = '*';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imprimo en consola
|
||||||
|
for (int i = 0; i < matriz.length; i++) {
|
||||||
|
for (int j = 0; j < matriz[i].length; j++) {
|
||||||
|
System.out.print(matriz[i][j]);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque10;
|
||||||
|
|
||||||
|
public class Ejercicio03_NumerosAlAzarHastaMediaProximaA500 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int numAzar, suma = 0, contador = 0;
|
||||||
|
float media;
|
||||||
|
|
||||||
|
|
||||||
|
do {
|
||||||
|
numAzar = (int) Math.round(Math.random() * 1000);
|
||||||
|
suma += numAzar;
|
||||||
|
contador++;
|
||||||
|
media = suma / (float) contador;
|
||||||
|
} while (media < 499.5 || media > 500.5);
|
||||||
|
|
||||||
|
System.out.println("He necesitado " + contador + " números para tener una media " +
|
||||||
|
" de " + media);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque10;
|
||||||
|
|
||||||
|
public class Ejercicio04_MatrizConBordeYCeroAlAzar {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Declaración de variables
|
||||||
|
char matriz[][] = new char[10][20];
|
||||||
|
int posicionAzarFila, posicionAzarColumna;
|
||||||
|
|
||||||
|
// La relleno de espacios en blanco
|
||||||
|
for (int i = 0; i < matriz.length; i++) {
|
||||||
|
for (int j = 0; j < matriz[i].length; j++) {
|
||||||
|
if (i == 0 || i == (matriz.length - 1) ||
|
||||||
|
j == 0 || j == (matriz[0].length - 1)) {
|
||||||
|
matriz[i][j] = '*';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
matriz[i][j] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posición del 0 con valores al azar en fila y columna
|
||||||
|
posicionAzarFila = (int) Math.round(Math.random() * (matriz.length - 2 - 1) + 1);
|
||||||
|
posicionAzarColumna = (int) Math.round(Math.random() * (matriz[0].length - 2 - 1) + 1);
|
||||||
|
// Coloco el cero
|
||||||
|
matriz[posicionAzarFila][posicionAzarColumna] = '0';
|
||||||
|
|
||||||
|
// Imprimo en consola
|
||||||
|
for (int i = 0; i < matriz.length; i++) {
|
||||||
|
for (int j = 0; j < matriz[i].length; j++) {
|
||||||
|
System.out.print(matriz[i][j]);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque10;
|
||||||
|
|
||||||
|
public class Ejercicio05_MatrizConBordeYCerosYUnosAlAzar {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Declaración de variables
|
||||||
|
char matriz[][] = new char[20][10];
|
||||||
|
int probabilidad50;
|
||||||
|
|
||||||
|
// La relleno de espacios en blanco
|
||||||
|
for (int i = 0; i < matriz.length; i++) {
|
||||||
|
for (int j = 0; j < matriz[i].length; j++) {
|
||||||
|
if (i == 0 || i == (matriz.length - 1) || j == 0 || j == (matriz[0].length - 1)) {
|
||||||
|
matriz[i][j] = '*';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Relleno de 0 y 1 al 50% de probabilidad
|
||||||
|
probabilidad50 = (int) Math.round(Math.random());
|
||||||
|
if (probabilidad50 == 0) {
|
||||||
|
matriz[i][j] = '0';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
matriz[i][j] = '1';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imprimo en consola
|
||||||
|
for (int i = 0; i < matriz.length; i++) {
|
||||||
|
for (int j = 0; j < matriz[i].length; j++) {
|
||||||
|
System.out.print(matriz[i][j]);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package tutorialJava.capitulo4_Arrays.ejercicios.bloque11;
|
||||||
|
|
||||||
|
public class Ejercicio01_OrdenarArrayDeStrings {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String palabras[] = new String[] {"aves", "mamiferos",
|
||||||
|
"reptiles", "insectos", "anfibios"};
|
||||||
|
|
||||||
|
ordenaBurbuja(palabras);
|
||||||
|
|
||||||
|
for (int i = 0; i < palabras.length; i++) {
|
||||||
|
System.out.println(palabras[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void ordenaBurbuja (String a[]) {
|
||||||
|
boolean hayIntercambios;
|
||||||
|
do {
|
||||||
|
hayIntercambios = false;
|
||||||
|
for (int i = 0; i < (a.length - 1); i++) {
|
||||||
|
if (comparaCadenas(a[i], a[i+1]) == 1) {
|
||||||
|
String aux = a[i];
|
||||||
|
a[i] = a[i + 1];
|
||||||
|
a[i + 1] = aux;
|
||||||
|
hayIntercambios = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (hayIntercambios == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static int comparaCadenas(String s1, String s2) {
|
||||||
|
|
||||||
|
int menorLongitud = (s1.length() < s2.length())? s1.length() : s2.length();
|
||||||
|
|
||||||
|
for (int i = 0; i < menorLongitud; i++) {
|
||||||
|
if (s1.charAt(i) < s2.charAt(i)) return -1;
|
||||||
|
else if (s1.charAt(i) > s2.charAt(i)) return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s1.length() == s2.length()) return 0;
|
||||||
|
return (s1.length() < s2.length())? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
60
src/tutorialJava/capitulo5/ej01_cromosBaloncesto/Cromo.java
Normal file
60
src/tutorialJava/capitulo5/ej01_cromosBaloncesto/Cromo.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package tutorialJava.capitulo5.ej01_cromosBaloncesto;
|
||||||
|
|
||||||
|
public class Cromo {
|
||||||
|
// Propiedades
|
||||||
|
protected String nombreJugador;
|
||||||
|
protected int puntuacion;
|
||||||
|
protected String equipo;
|
||||||
|
|
||||||
|
public Cromo() {
|
||||||
|
this.nombreJugador = "Jugador por defecto";
|
||||||
|
this.puntuacion = 0;
|
||||||
|
this.equipo = "Sin equipo";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cromo(String nombreJugador, int puntuacion, String equipo) {
|
||||||
|
this.nombreJugador = nombreJugador;
|
||||||
|
this.puntuacion = puntuacion;
|
||||||
|
this.equipo = equipo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void agregaMinimaPuntuacion() {
|
||||||
|
this.puntuacion++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getNombreJugador() {
|
||||||
|
return nombreJugador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombreJugador(String nombreJugador) {
|
||||||
|
this.nombreJugador = nombreJugador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPuntuacion() {
|
||||||
|
return puntuacion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPuntuacion(int puntuacion) {
|
||||||
|
this.puntuacion = puntuacion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEquipo() {
|
||||||
|
return equipo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEquipo(String equipo) {
|
||||||
|
this.equipo = equipo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Cromo [nombreJugador=" + nombreJugador + ", puntuacion=" + puntuacion + ", equipo=" + equipo + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package tutorialJava.capitulo5.ej01_cromosBaloncesto;
|
||||||
|
|
||||||
|
public class CromoBaloncesto extends Cromo {
|
||||||
|
|
||||||
|
private int altura;
|
||||||
|
|
||||||
|
|
||||||
|
public CromoBaloncesto() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CromoBaloncesto(String nombreJugador, int puntuacion, String equipo) {
|
||||||
|
super(nombreJugador, puntuacion, equipo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void agregaMinimaPuntuacion() {
|
||||||
|
this.setPuntuacion(this.getPuntuacion() + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CromoBaloncesto [getNombreJugador()=" + getNombreJugador() + ", getPuntuacion()=" + getPuntuacion()
|
||||||
|
+ ", getEquipo()=" + getEquipo() + ", altura=" + altura + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package tutorialJava.capitulo5.ej01_cromosBaloncesto;
|
||||||
|
|
||||||
|
public class CromoFutbol extends Cromo {
|
||||||
|
|
||||||
|
public CromoFutbol() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public CromoFutbol(String nombreJugador, int puntuacion, String equipo) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package tutorialJava.capitulo5.ej01_cromosBaloncesto;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Cromo cromoSimple = new Cromo("Iniesta", 1000, "España");
|
||||||
|
System.out.println("Id del cromo: " + cromoSimple.hashCode());
|
||||||
|
System.out.println(cromoSimple.toString());
|
||||||
|
|
||||||
|
|
||||||
|
CromoBaloncesto cromo1 = new CromoBaloncesto("Ricky", 100, "Barcelona");
|
||||||
|
System.out.println("Id del cromo: " + cromo1.hashCode());
|
||||||
|
System.out.println(cromo1.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
package tutorialJava.capitulo5.ej02_independenceDay;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class CampoBatalla {
|
||||||
|
|
||||||
|
private String nombre;
|
||||||
|
private Humano humanos[] = new Humano[20];
|
||||||
|
private Malvado malvados[] = new Malvado[20];
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param nombre
|
||||||
|
*/
|
||||||
|
public CampoBatalla (String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
|
||||||
|
for (int i = 0; i < humanos.length; i++) {
|
||||||
|
humanos[i] = new Humano("H-" + i);
|
||||||
|
}
|
||||||
|
// humanos[humanos.length - 1].setPuntosVida(
|
||||||
|
// humanos[humanos.length - 1].getPuntosVida() * 2);
|
||||||
|
|
||||||
|
Humano ultimoHumano = humanos[humanos.length - 1];
|
||||||
|
ultimoHumano.setPuntosVida(ultimoHumano.getPuntosVida() * 2);
|
||||||
|
|
||||||
|
for (int i = 0; i < malvados.length; i++) {
|
||||||
|
malvados[i] = new Malvado("M-" + i);
|
||||||
|
}
|
||||||
|
// Establezco el doble de puntos de vida al último malvado
|
||||||
|
Malvado ultimoMalvado = malvados[malvados.length - 1];
|
||||||
|
ultimoMalvado.setPuntosVida(ultimoMalvado.getPuntosVida() * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void mezclaHumanos () {
|
||||||
|
for (int i = 0; i < humanos.length; i++) {
|
||||||
|
int ind1 = Utils.obtenerNumeroAzar(0, humanos.length - 1);
|
||||||
|
int ind2 = Utils.obtenerNumeroAzar(0, humanos.length - 1);
|
||||||
|
Humano aux = humanos[ind1];
|
||||||
|
humanos[ind1] = humanos[ind2];
|
||||||
|
humanos[ind2] = aux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mezclaMalvados () {
|
||||||
|
for (int i = 0; i < malvados.length; i++) {
|
||||||
|
int ind1 = Utils.obtenerNumeroAzar(0, malvados.length - 1);
|
||||||
|
int ind2 = Utils.obtenerNumeroAzar(0, malvados.length - 1);
|
||||||
|
Malvado aux = malvados[ind1];
|
||||||
|
malvados[ind1] = malvados[ind2];
|
||||||
|
malvados[ind2] = aux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void batalla () {
|
||||||
|
do {
|
||||||
|
// Disparo sobre el primer malvado vivo
|
||||||
|
Malvado m = getPrimerMalvadoVivo();
|
||||||
|
m.setPuntosVida(m.getPuntosVida() -
|
||||||
|
Utils.obtenerNumeroAzar(5, 25));
|
||||||
|
if (m.getPuntosVida() <= 0) {
|
||||||
|
m.setVivo(false);
|
||||||
|
m.setPuntosVida(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sólo si queda algún malvado vivo, disparo sobre humano
|
||||||
|
if (getPrimerMalvadoVivo() != null) {
|
||||||
|
// Disparo sobre el primer humano vivo
|
||||||
|
Humano h = getPrimerHumanoVivo();
|
||||||
|
h.setPuntosVida(h.getPuntosVida() -
|
||||||
|
Utils.obtenerNumeroAzar(5, 25));
|
||||||
|
if (h.getPuntosVida() <= 0) {
|
||||||
|
h.setVivo(false);
|
||||||
|
h.setPuntosVida(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imprimo campo de batalla
|
||||||
|
System.out.println(toString());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
} while(getPrimerHumanoVivo() != null &&
|
||||||
|
getPrimerMalvadoVivo() != null);
|
||||||
|
|
||||||
|
// Si llego hasta aquí, un bando no tiene soldados vivos
|
||||||
|
if (getPrimerHumanoVivo() != null) {
|
||||||
|
System.out.println("Han ganado los humanos");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Han ganado los malvados");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Humano getPrimerHumanoVivo() {
|
||||||
|
for (int i = 0; i < humanos.length; i++) {
|
||||||
|
if (humanos[i].isVivo()) {
|
||||||
|
return humanos[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Malvado getPrimerMalvadoVivo() {
|
||||||
|
for (int i = 0; i < malvados.length; i++) {
|
||||||
|
if (malvados[i].isVivo()) {
|
||||||
|
return malvados[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Humano[] getHumanos() {
|
||||||
|
return humanos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHumanos(Humano[] humanos) {
|
||||||
|
this.humanos = humanos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Malvado[] getMalvados() {
|
||||||
|
return malvados;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMalvados(Malvado[] malvados) {
|
||||||
|
this.malvados = malvados;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuffer sb = new StringBuffer("Campo: " + this.nombre);
|
||||||
|
sb.append("\nHumanos: ");
|
||||||
|
for (int i = 0; i < humanos.length; i++) {
|
||||||
|
if (humanos[i].isVivo()) {
|
||||||
|
sb.append(humanos[i].getNombre() + ":" +
|
||||||
|
humanos[i].getPuntosVida() + ":" +
|
||||||
|
humanos[i].isVivo() + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("\nMalvados: ");
|
||||||
|
for (int i = 0; i < malvados.length; i++) {
|
||||||
|
if (malvados[i].isVivo()) {
|
||||||
|
sb.append(malvados[i].getNombre() + ":" +
|
||||||
|
malvados[i].getPuntosVida() + ":" +
|
||||||
|
malvados[i].isVivo() + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
62
src/tutorialJava/capitulo5/ej02_independenceDay/Humano.java
Normal file
62
src/tutorialJava/capitulo5/ej02_independenceDay/Humano.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package tutorialJava.capitulo5.ej02_independenceDay;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class Humano {
|
||||||
|
|
||||||
|
private int puntosVida;
|
||||||
|
private String nombre;
|
||||||
|
private boolean vivo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Humano() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param puntosVida
|
||||||
|
* @param nombre
|
||||||
|
* @param vivo
|
||||||
|
*/
|
||||||
|
public Humano(String nombre) {
|
||||||
|
puntosVida = Utils.obtenerNumeroAzar(50, 100);
|
||||||
|
this.nombre = nombre;
|
||||||
|
vivo = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPuntosVida() {
|
||||||
|
return puntosVida;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPuntosVida(int puntosVida) {
|
||||||
|
this.puntosVida = puntosVida;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVivo() {
|
||||||
|
return vivo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVivo(boolean vivo) {
|
||||||
|
this.vivo = vivo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Humano [puntosVida=" + puntosVida + ", nombre=" + nombre + ", vivo=" + vivo + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
53
src/tutorialJava/capitulo5/ej02_independenceDay/Malvado.java
Normal file
53
src/tutorialJava/capitulo5/ej02_independenceDay/Malvado.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package tutorialJava.capitulo5.ej02_independenceDay;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class Malvado {
|
||||||
|
|
||||||
|
private int puntosVida;
|
||||||
|
private String nombre;
|
||||||
|
private boolean vivo;
|
||||||
|
|
||||||
|
public Malvado() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Malvado(String nombre) {
|
||||||
|
this.puntosVida = Utils.obtenerNumeroAzar(50, 100);
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.vivo = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPuntosVida() {
|
||||||
|
return puntosVida;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPuntosVida(int puntosVida) {
|
||||||
|
this.puntosVida = puntosVida;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVivo() {
|
||||||
|
return vivo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVivo(boolean vivo) {
|
||||||
|
this.vivo = vivo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Malvador [puntosVida=" + puntosVida + ", nombre=" + nombre + ", vivo=" + vivo + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package tutorialJava.capitulo5.ej02_independenceDay;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
CampoBatalla campo = new CampoBatalla("Rute");
|
||||||
|
|
||||||
|
campo.mezclaHumanos();
|
||||||
|
campo.mezclaMalvados();
|
||||||
|
System.out.println(campo.toString());
|
||||||
|
|
||||||
|
campo.batalla();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package tutorialJava.capitulo5.ej03_independenceDayConHerencia;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class CampoBatalla {
|
||||||
|
|
||||||
|
private String nombre;
|
||||||
|
private Humano humanos[] = new Humano[20];
|
||||||
|
private Malvado malvados[] = new Malvado[20];
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param nombre
|
||||||
|
*/
|
||||||
|
public CampoBatalla (String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
|
||||||
|
for (int i = 0; i < humanos.length; i++) {
|
||||||
|
humanos[i] = new Humano("H-" + i);
|
||||||
|
}
|
||||||
|
// humanos[humanos.length - 1].setPuntosVida(
|
||||||
|
// humanos[humanos.length - 1].getPuntosVida() * 2);
|
||||||
|
|
||||||
|
Humano ultimoHumano = humanos[humanos.length - 1];
|
||||||
|
ultimoHumano.setPuntosVida(ultimoHumano.getPuntosVida() * 2);
|
||||||
|
|
||||||
|
for (int i = 0; i < malvados.length; i++) {
|
||||||
|
malvados[i] = new Malvado("M-" + i);
|
||||||
|
}
|
||||||
|
// Establezco el doble de puntos de vida al último malvado
|
||||||
|
Malvado ultimoMalvado = malvados[malvados.length - 1];
|
||||||
|
ultimoMalvado.setPuntosVida(ultimoMalvado.getPuntosVida() * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void mezclaPersonajes (Personaje a[]) {
|
||||||
|
for (int i = 0; i < a.length; i++) {
|
||||||
|
int ind1 = Utils.obtenerNumeroAzar(0, a.length - 1);
|
||||||
|
int ind2 = Utils.obtenerNumeroAzar(0, a.length - 1);
|
||||||
|
Personaje aux = a[ind1];
|
||||||
|
a[ind1] = a[ind2];
|
||||||
|
a[ind2] = aux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void batalla () {
|
||||||
|
do {
|
||||||
|
// Disparo sobre el primer malvado vivo
|
||||||
|
Malvado m = (Malvado) getPrimerPersonajeVivo(malvados);
|
||||||
|
m.setPuntosVida(m.getPuntosVida() -
|
||||||
|
Utils.obtenerNumeroAzar(5, 25));
|
||||||
|
if (m.getPuntosVida() <= 0) {
|
||||||
|
m.setVivo(false);
|
||||||
|
m.setPuntosVida(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sólo si queda algún malvado vivo, disparo sobre humano
|
||||||
|
if (getPrimerPersonajeVivo(malvados) != null) {
|
||||||
|
// Disparo sobre el primer humano vivo
|
||||||
|
Humano h = (Humano) getPrimerPersonajeVivo(humanos);
|
||||||
|
h.setPuntosVida(h.getPuntosVida() -
|
||||||
|
Utils.obtenerNumeroAzar(5, 25));
|
||||||
|
if (h.getPuntosVida() <= 0) {
|
||||||
|
h.setVivo(false);
|
||||||
|
h.setPuntosVida(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imprimo campo de batalla
|
||||||
|
System.out.println(toString());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
} while(getPrimerPersonajeVivo(humanos) != null &&
|
||||||
|
getPrimerPersonajeVivo(malvados) != null);
|
||||||
|
|
||||||
|
// Si llego hasta aquí, un bando no tiene soldados vivos
|
||||||
|
if (getPrimerPersonajeVivo(humanos) != null) {
|
||||||
|
System.out.println("Han ganado los humanos");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Han ganado los malvados");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Personaje getPrimerPersonajeVivo(Personaje a[]) {
|
||||||
|
for (int i = 0; i < a.length; i++) {
|
||||||
|
if (a[i].isVivo()) {
|
||||||
|
return a[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Humano[] getHumanos() {
|
||||||
|
return humanos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHumanos(Humano[] humanos) {
|
||||||
|
this.humanos = humanos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Malvado[] getMalvados() {
|
||||||
|
return malvados;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMalvados(Malvado[] malvados) {
|
||||||
|
this.malvados = malvados;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuffer sb = new StringBuffer("Campo: " + this.nombre);
|
||||||
|
sb.append("\nHumanos: ");
|
||||||
|
for (int i = 0; i < humanos.length; i++) {
|
||||||
|
if (humanos[i].isVivo()) {
|
||||||
|
sb.append(humanos[i].getNombre() + ":" +
|
||||||
|
humanos[i].getPuntosVida() + ":" +
|
||||||
|
humanos[i].isVivo() + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("\nMalvados: ");
|
||||||
|
for (int i = 0; i < malvados.length; i++) {
|
||||||
|
if (malvados[i].isVivo()) {
|
||||||
|
sb.append(malvados[i].getNombre() + ":" +
|
||||||
|
malvados[i].getPuntosVida() + ":" +
|
||||||
|
malvados[i].isVivo() + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package tutorialJava.capitulo5.ej03_independenceDayConHerencia;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class Humano extends Personaje {
|
||||||
|
|
||||||
|
public int altura;
|
||||||
|
|
||||||
|
public Humano() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Humano(String nombre) {
|
||||||
|
super(nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package tutorialJava.capitulo5.ej03_independenceDayConHerencia;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class Malvado extends Personaje {
|
||||||
|
|
||||||
|
public Malvado() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Malvado(String nombre) {
|
||||||
|
super(nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package tutorialJava.capitulo5.ej03_independenceDayConHerencia;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class Personaje {
|
||||||
|
|
||||||
|
private int puntosVida;
|
||||||
|
private String nombre;
|
||||||
|
private boolean vivo;
|
||||||
|
|
||||||
|
public Personaje() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Personaje(String nombre) {
|
||||||
|
super();
|
||||||
|
this.puntosVida = Utils.obtenerNumeroAzar(50, 100);
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.vivo = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Personaje(int puntosVida, String nombre, boolean vivo) {
|
||||||
|
super();
|
||||||
|
this.puntosVida = puntosVida;
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.vivo = vivo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPuntosVida() {
|
||||||
|
return puntosVida;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPuntosVida(int puntosVida) {
|
||||||
|
this.puntosVida = puntosVida;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVivo() {
|
||||||
|
return vivo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVivo(boolean vivo) {
|
||||||
|
this.vivo = vivo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Personaje [puntosVida=" + puntosVida + ", nombre=" + nombre + ", vivo=" + vivo + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package tutorialJava.capitulo5.ej03_independenceDayConHerencia;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
CampoBatalla campo = new CampoBatalla("Rute");
|
||||||
|
|
||||||
|
campo.mezclaPersonajes(campo.getHumanos());
|
||||||
|
campo.mezclaPersonajes(campo.getMalvados());
|
||||||
|
System.out.println(campo.toString());
|
||||||
|
|
||||||
|
campo.batalla();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package tutorialJava.capitulo5.ej04_EjemploAbstraccionFiguras;
|
||||||
|
|
||||||
|
public class Circulo extends Figura {
|
||||||
|
|
||||||
|
private float radio;
|
||||||
|
|
||||||
|
public Circulo(float radio) {
|
||||||
|
this.radio = radio;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float calcularArea() {
|
||||||
|
return (float) (Math.PI * this.radio * this.radio);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float calcularPerimetro() {
|
||||||
|
return (float) (2 * Math.PI * this.radio);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package tutorialJava.capitulo5.ej04_EjemploAbstraccionFiguras;
|
||||||
|
|
||||||
|
public abstract class Figura {
|
||||||
|
|
||||||
|
public abstract float calcularArea();
|
||||||
|
public abstract float calcularPerimetro();
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Área: " + calcularArea() +
|
||||||
|
" - Perímetro: " + calcularPerimetro();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package tutorialJava.capitulo5.ej04_EjemploAbstraccionFiguras;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Figura figuras[] = new Figura[2];
|
||||||
|
figuras[0] = new Circulo(1.4f);
|
||||||
|
figuras[1] = new Rectangulo(2, 4);
|
||||||
|
|
||||||
|
for (int i = 0; i < figuras.length; i++) {
|
||||||
|
System.out.println(figuras[i].toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package tutorialJava.capitulo5.ej04_EjemploAbstraccionFiguras;
|
||||||
|
|
||||||
|
public class Rectangulo extends Figura {
|
||||||
|
|
||||||
|
private float base;
|
||||||
|
private float altura;
|
||||||
|
|
||||||
|
public Rectangulo(float base, float altura) {
|
||||||
|
this.base = base;
|
||||||
|
this.altura = altura;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float calcularArea() {
|
||||||
|
return this.base * this.altura;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float calcularPerimetro() {
|
||||||
|
return 2 * this.base + 2 * this.altura;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package tutorialJava.capitulo5.ej05_EjemploUsoVariableEstatica;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
Usuario u = new Usuario();
|
||||||
|
System.out.println(u.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package tutorialJava.capitulo5.ej05_EjemploUsoVariableEstatica;
|
||||||
|
|
||||||
|
public class Usuario {
|
||||||
|
|
||||||
|
private static int CONTADOR_USUARIOS = 1;
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
public Usuario() {
|
||||||
|
super();
|
||||||
|
this.id = "Usuario_" + CONTADOR_USUARIOS;
|
||||||
|
CONTADOR_USUARIOS++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Usuario [id=" + id + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
37
src/tutorialJava/capitulo5/ej06_PatronSingleton/Player.java
Normal file
37
src/tutorialJava/capitulo5/ej06_PatronSingleton/Player.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package tutorialJava.capitulo5.ej06_PatronSingleton;
|
||||||
|
|
||||||
|
public class Player {
|
||||||
|
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
private static Player instance = null; // Singleton
|
||||||
|
|
||||||
|
// Singleton
|
||||||
|
public static Player getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new Player("Nave");
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player(String nombre) {
|
||||||
|
super();
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Player [nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package tutorialJava.capitulo5.ej06_PatronSingleton;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// Desde un localizador de colisiones
|
||||||
|
System.out.println("Llamada 1: " + Player.getInstance());
|
||||||
|
|
||||||
|
System.out.println("Llamada 2: " + Player.getInstance());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package tutorialJava.capitulo5.ej07_InterfaceWindowListener;
|
||||||
|
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.awt.event.WindowListener;
|
||||||
|
|
||||||
|
public class KKListener implements WindowListener, MouseListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowOpened(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowClosed(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowIconified(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowDeiconified(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowActivated(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowDeactivated(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package tutorialJava.capitulo5.ej07_InterfaceWindowListener;
|
||||||
|
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.awt.event.WindowListener;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
JFrame ventana = new JFrame("Título de la ventana");
|
||||||
|
ventana.setBounds(0, 0, 800, 600);
|
||||||
|
ventana.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
ventana.addWindowListener(new WindowAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
super.windowClosing(e);
|
||||||
|
}});
|
||||||
|
|
||||||
|
ventana.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque01_ArrayPersonas;
|
||||||
|
|
||||||
|
public class Persona {
|
||||||
|
|
||||||
|
private String nombre;
|
||||||
|
private String apellidos;
|
||||||
|
private String dni;
|
||||||
|
private String direccion;
|
||||||
|
private String telefono;
|
||||||
|
|
||||||
|
|
||||||
|
public Persona() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Persona(String nombre, String apellidos, String dni, String direccion, String telefono) {
|
||||||
|
super();
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.apellidos = apellidos;
|
||||||
|
this.dni = dni;
|
||||||
|
this.direccion = direccion;
|
||||||
|
this.telefono = telefono;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getApellidos() {
|
||||||
|
return apellidos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setApellidos(String apellidos) {
|
||||||
|
this.apellidos = apellidos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getDni() {
|
||||||
|
return dni;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setDni(String dni) {
|
||||||
|
this.dni = dni;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getDireccion() {
|
||||||
|
return direccion;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setDireccion(String direccion) {
|
||||||
|
this.direccion = direccion;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getTelefono() {
|
||||||
|
return telefono;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setTelefono(String telefono) {
|
||||||
|
this.telefono = telefono;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Persona [nombre=" + nombre + ", apellidos=" + apellidos + ", dni=" + dni + ", direccion=" + direccion
|
||||||
|
+ ", telefono=" + telefono + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque01_ArrayPersonas;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
|
||||||
|
private static Persona personas[] = new Persona[3];
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int opcion = 0;
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
do {
|
||||||
|
opcion = muestraMenu();
|
||||||
|
|
||||||
|
switch (opcion) {
|
||||||
|
case 1:
|
||||||
|
for (int i = 0; i < personas.length; i++) {
|
||||||
|
personas[i] = new Persona();
|
||||||
|
System.out.println("Introduzca nombre de persona");
|
||||||
|
personas[i].setNombre(sc.nextLine());
|
||||||
|
System.out.println("Introduzca apellidos de persona");
|
||||||
|
personas[i].setApellidos(sc.nextLine());
|
||||||
|
System.out.println("Introduzca dni de persona");
|
||||||
|
personas[i].setDni(sc.nextLine());
|
||||||
|
System.out.println("Introduzca dirección de persona");
|
||||||
|
personas[i].setDireccion(sc.nextLine());
|
||||||
|
System.out.println("Introduzca telefono de persona");
|
||||||
|
personas[i].setTelefono(sc.nextLine());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
for (int i = 0; i < personas.length; i++) {
|
||||||
|
System.out.println(personas[i].toString());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (opcion != 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static int muestraMenu() {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.println("\n\nMenú" +
|
||||||
|
"\n0.- Salir" +
|
||||||
|
"\n1.- Introducir datos" +
|
||||||
|
"\n2.- Visualizar datos" +
|
||||||
|
"\n\tIntroduzca su opción: ");
|
||||||
|
return Integer.parseInt(sc.nextLine());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque02.articulosComestibles;
|
||||||
|
|
||||||
|
public class ArtNoPerecedero extends Articulo {
|
||||||
|
|
||||||
|
public ArtNoPerecedero() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtNoPerecedero(String codigo, String nombre, float precio) {
|
||||||
|
super(codigo, nombre, precio);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque02.articulosComestibles;
|
||||||
|
|
||||||
|
public class ArtPerecedero extends Articulo {
|
||||||
|
|
||||||
|
private String fechaCaducidad;
|
||||||
|
|
||||||
|
public ArtPerecedero() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtPerecedero(String codigo, String nombre, float precio) {
|
||||||
|
super(codigo, nombre, precio);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFechaCaducidad() {
|
||||||
|
return fechaCaducidad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFechaCaducidad(String fechaCaducidad) {
|
||||||
|
this.fechaCaducidad = fechaCaducidad;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ArtPerecedero [fechaCaducidad=" + fechaCaducidad + ", getCodigo()=" + getCodigo() + ", getNombre()="
|
||||||
|
+ getNombre() + ", getPrecio()=" + getPrecio() + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque02.articulosComestibles;
|
||||||
|
|
||||||
|
public class Articulo {
|
||||||
|
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
private float precio;
|
||||||
|
|
||||||
|
public Articulo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Articulo(String codigo, String nombre, float precio) {
|
||||||
|
super();
|
||||||
|
this.codigo = codigo;
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.precio = precio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCodigo() {
|
||||||
|
return codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodigo(String codigo) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPrecio() {
|
||||||
|
return precio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrecio(float precio) {
|
||||||
|
this.precio = precio;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Articulo [codigo=" + codigo + ", nombre=" + nombre + ", precio=" + precio + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque02.articulosComestibles;
|
||||||
|
|
||||||
|
import tutorialJava.Utils;
|
||||||
|
|
||||||
|
public class Tienda {
|
||||||
|
|
||||||
|
public Tienda() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
Articulo articulos[] = new Articulo[4];
|
||||||
|
|
||||||
|
for (int i = 0; i < articulos.length; i++) {
|
||||||
|
if (i < 2) {
|
||||||
|
System.out.println("Introduzca datos de Art perecedero: ");
|
||||||
|
ArtPerecedero artPer = new ArtPerecedero();
|
||||||
|
artPer.setCodigo(Utils.
|
||||||
|
obtenerCadenaConDescripcion("Dame código:"));
|
||||||
|
artPer.setNombre(Utils.
|
||||||
|
obtenerCadenaConDescripcion("Dame nombre:"));
|
||||||
|
artPer.setPrecio(Utils.
|
||||||
|
pideNumeroFloat("Dame precio"));
|
||||||
|
artPer.setFechaCaducidad(Utils.
|
||||||
|
obtenerCadenaConDescripcion("Dame fecha caducidad:"));
|
||||||
|
articulos[i] = artPer;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Introduzca datos de Art perecedero: ");
|
||||||
|
ArtNoPerecedero artNoPer = new ArtNoPerecedero();
|
||||||
|
artNoPer.setCodigo(Utils.
|
||||||
|
obtenerCadenaConDescripcion("Dame código:"));
|
||||||
|
artNoPer.setNombre(Utils.
|
||||||
|
obtenerCadenaConDescripcion("Dame nombre:"));
|
||||||
|
artNoPer.setPrecio(Utils.
|
||||||
|
pideNumeroFloat("Dame precio"));
|
||||||
|
articulos[i] = artNoPer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestro los valores
|
||||||
|
for (int i = 0; i < articulos.length; i++) {
|
||||||
|
System.out.println(articulos[i].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque02.coleccionAntiguedades;
|
||||||
|
|
||||||
|
public class Antiguedad {
|
||||||
|
|
||||||
|
private int anio;
|
||||||
|
private String origen;
|
||||||
|
private float precio;
|
||||||
|
|
||||||
|
public Antiguedad() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Antiguedad(int anio, String origen, float precio) {
|
||||||
|
super();
|
||||||
|
this.anio = anio;
|
||||||
|
this.origen = origen;
|
||||||
|
this.precio = precio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAnio() {
|
||||||
|
return anio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAnio(int anio) {
|
||||||
|
this.anio = anio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrigen() {
|
||||||
|
return origen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrigen(String origen) {
|
||||||
|
this.origen = origen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPrecio() {
|
||||||
|
return precio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrecio(float precio) {
|
||||||
|
this.precio = precio;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Antiguedad [anio=" + anio + ", origen=" + origen + ", precio=" + precio + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque02.coleccionAntiguedades;
|
||||||
|
|
||||||
|
public class Joya extends Antiguedad {
|
||||||
|
|
||||||
|
private String material;
|
||||||
|
|
||||||
|
public Joya() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Joya(int anio, String origen, float precio) {
|
||||||
|
super(anio, origen, precio);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaterial() {
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterial(String material) {
|
||||||
|
this.material = material;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " material: " + this.material;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.instrumentos;
|
||||||
|
|
||||||
|
class Bateria extends Instrumento {
|
||||||
|
public Bateria(String nombre) {
|
||||||
|
super(nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tocar() {
|
||||||
|
System.out.println(nombre + " (Batería): Marcando el ritmo con tambores");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.instrumentos;
|
||||||
|
|
||||||
|
class Guitarra extends Instrumento {
|
||||||
|
public Guitarra(String nombre) {
|
||||||
|
super(nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tocar() {
|
||||||
|
System.out.println(nombre + " (Guitarra): Tocando acordes de rock");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.instrumentos;
|
||||||
|
|
||||||
|
abstract class Instrumento {
|
||||||
|
protected String nombre;
|
||||||
|
|
||||||
|
public Instrumento(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método abstracto
|
||||||
|
public abstract void tocar();
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.instrumentos;
|
||||||
|
|
||||||
|
class Piano extends Instrumento {
|
||||||
|
public Piano(String nombre) {
|
||||||
|
super(nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tocar() {
|
||||||
|
System.out.println(nombre + " (Piano): Tocando una melodía clásica");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.instrumentos;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Crear una lista de instrumentos
|
||||||
|
Instrumento[] instrumentos = new Instrumento[] {
|
||||||
|
new Guitarra("Fender Stratocaster"),
|
||||||
|
new Piano("Yamaha U1"),
|
||||||
|
new Bateria("Pearl Export"),
|
||||||
|
new Guitarra("Gibson Les Paul")
|
||||||
|
};
|
||||||
|
|
||||||
|
// Recorrer la lista y llamar al método tocar() de cada instrumento
|
||||||
|
for (Instrumento instrumento : instrumentos) {
|
||||||
|
instrumento.tocar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.sonidosAnimales;
|
||||||
|
|
||||||
|
abstract class Animal {
|
||||||
|
protected String nombre;
|
||||||
|
|
||||||
|
public Animal(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método abstracto
|
||||||
|
public abstract void emitirSonido();
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Animal [nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.sonidosAnimales;
|
||||||
|
|
||||||
|
class Gato extends Animal {
|
||||||
|
public Gato(String nombre) {
|
||||||
|
super(nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void emitirSonido() {
|
||||||
|
System.out.println(nombre + " dice: ¡Miau, miau!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.sonidosAnimales;
|
||||||
|
|
||||||
|
class Perro extends Animal {
|
||||||
|
public Perro(String nombre) {
|
||||||
|
super(nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void emitirSonido() {
|
||||||
|
System.out.println(nombre + " dice: ¡Guau, guau!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.sonidosAnimales;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
int a[] = new int[] {1, 2, 3};
|
||||||
|
|
||||||
|
// Crear un array de tipo Animal
|
||||||
|
Animal[] animales = new Animal[] {
|
||||||
|
new Perro("Max"),
|
||||||
|
new Gato("Luna"),
|
||||||
|
new Perro("Buddy"),
|
||||||
|
new Gato("Mimi")
|
||||||
|
};
|
||||||
|
|
||||||
|
// Llamar al método emitirSonido() para cada animal
|
||||||
|
for (Animal animal : animales) {
|
||||||
|
System.out.println("Animal: ");
|
||||||
|
animal.emitirSonido();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.vehiculos;
|
||||||
|
|
||||||
|
class Bicicleta extends Vehiculo {
|
||||||
|
public Bicicleta(String modelo) {
|
||||||
|
super(modelo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acelerar() {
|
||||||
|
velocidadActual += 5; // Incrementa velocidad en 5
|
||||||
|
System.out.println(modelo + " (Bicicleta) acelera a " + velocidadActual + " km/h");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void frenar() {
|
||||||
|
velocidadActual = Math.max(0, velocidadActual - 3); // Reduce velocidad en 3
|
||||||
|
System.out.println(modelo + " (Bicicleta) frena a " + velocidadActual + " km/h");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.vehiculos;
|
||||||
|
|
||||||
|
class Coche extends Vehiculo {
|
||||||
|
public Coche(String modelo) {
|
||||||
|
super(modelo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acelerar() {
|
||||||
|
velocidadActual += 20; // Incrementa velocidad en 20
|
||||||
|
System.out.println(modelo + " (Coche) acelera a " + velocidadActual + " km/h");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void frenar() {
|
||||||
|
velocidadActual = Math.max(0, velocidadActual - 15); // Reduce velocidad en 15
|
||||||
|
System.out.println(modelo + " (Coche) frena a " + velocidadActual + " km/h");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.vehiculos;
|
||||||
|
|
||||||
|
public class Principal {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Crear instancias de vehículos
|
||||||
|
Vehiculo[] vehiculos = new Vehiculo[] {
|
||||||
|
new Coche("Toyota Corolla"),
|
||||||
|
new Bicicleta("BMX Pro"),
|
||||||
|
new Coche("Ford Mustang"),
|
||||||
|
new Bicicleta("Mountain Bike")
|
||||||
|
};
|
||||||
|
|
||||||
|
// Simular la aceleración y el frenado
|
||||||
|
for (Vehiculo vehiculo : vehiculos) {
|
||||||
|
System.out.println("Vehículo: " + vehiculo.getModelo());
|
||||||
|
vehiculo.acelerar();
|
||||||
|
vehiculo.acelerar();
|
||||||
|
vehiculo.frenar();
|
||||||
|
System.out.println("------------------------");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package tutorialJava.capitulo5.ejercicios.bloque03_clasesYMetodosAbstractos.vehiculos;
|
||||||
|
|
||||||
|
abstract class Vehiculo {
|
||||||
|
protected int velocidadActual;
|
||||||
|
protected String modelo;
|
||||||
|
|
||||||
|
public Vehiculo(String modelo) {
|
||||||
|
this.modelo = modelo;
|
||||||
|
this.velocidadActual = 0; // La velocidad inicial es 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Métodos abstractos
|
||||||
|
public abstract void acelerar();
|
||||||
|
public abstract void frenar();
|
||||||
|
|
||||||
|
public int getVelocidadActual() {
|
||||||
|
return velocidadActual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModelo() {
|
||||||
|
return modelo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVelocidadActual(int velocidadActual) {
|
||||||
|
this.velocidadActual = velocidadActual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModelo(String modelo) {
|
||||||
|
this.modelo = modelo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Vehiculo [velocidadActual=" + velocidadActual + ", modelo=" + modelo + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user