diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7da6d15..b6366bc 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,12 +4,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
@@ -38,22 +38,24 @@
- {
- "keyToString": {
- "Application.Ejercicio_a.executor": "Run",
- "Application.Ejercicio_b.executor": "Run",
- "Application.Ejercicio_c.executor": "Run",
- "Application.Ejercicio_d.executor": "Run",
- "Application.Ejercicio_e.executor": "Run",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.git.unshallow": "true",
- "git-widget-placeholder": "main",
- "kotlin-language-version-configured": "true",
- "onboarding.tips.debug.path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/net/h4ckx0r/Main.java"
+
+}]]>
+
@@ -147,7 +149,15 @@
1729857949405
-
+
+
+ 1732277745346
+
+
+
+ 1732277745346
+
+
@@ -172,6 +182,8 @@
-
+
+
+
\ No newline at end of file
diff --git a/src/main/java/examenes/examen20241213/Animal.java b/src/main/java/examenes/examen20241213/Animal.java
new file mode 100644
index 0000000..4e605b7
--- /dev/null
+++ b/src/main/java/examenes/examen20241213/Animal.java
@@ -0,0 +1,52 @@
+package examenes.examen20241213;
+
+import examenes.examen20241213.utils.Utils;
+
+public abstract class Animal {
+ private String nombre;
+ private float peso = Utils.generarFloatAleatorioEntreLimites(1, 600);
+ private float espacio = calcularEspacio();
+
+ private static int CONTADOR_ANIMALES = 0;
+
+ public Animal() {
+ this.nombre = "Animal-" + CONTADOR_ANIMALES;
+ CONTADOR_ANIMALES++;
+ }
+
+
+ public abstract float calcularEspacio();
+
+ public String getNombre() {
+ return nombre;
+ }
+
+ public void setNombre(String nombre) {
+ this.nombre = nombre;
+ }
+
+ public float getPeso() {
+ return peso;
+ }
+
+ public void setPeso(float peso) {
+ this.peso = peso;
+ }
+
+ public float getEspacio() {
+ return espacio;
+ }
+
+ public void setEspacio(float espacio) {
+ this.espacio = espacio;
+ }
+
+ @Override
+ public String toString() {
+ return "Animal{" +
+ "nombre='" + nombre + '\'' +
+ ", peso=" + peso +
+ ", espacio=" + espacio +
+ '}';
+ }
+}
diff --git a/src/main/java/examenes/examen20241213/Ave.java b/src/main/java/examenes/examen20241213/Ave.java
new file mode 100644
index 0000000..3ce2e25
--- /dev/null
+++ b/src/main/java/examenes/examen20241213/Ave.java
@@ -0,0 +1,33 @@
+package examenes.examen20241213;
+
+import examenes.examen20241213.utils.Utils;
+
+public class Ave extends Animal {
+ private float envergaduraAlas = Utils.generarFloatAleatorioEntreLimites(15, 200);
+
+ public Ave() {
+ }
+
+ @Override
+ public float calcularEspacio() {
+ return (float) (getPeso() * 1.5 + envergaduraAlas * 2);
+ }
+
+ public float getEnvergaduraAlas() {
+ return envergaduraAlas;
+ }
+
+ public void setEnvergaduraAlas(float envergaduraAlas) {
+ this.envergaduraAlas = envergaduraAlas;
+ }
+
+ @Override
+ public String toString() {
+ return "Ave{" +
+ "nombre='" + getNombre() + '\'' +
+ ", peso=" + getPeso() +
+ ", envergaduraAlas=" + envergaduraAlas +
+ ", espacio=" + getEspacio() +
+ '}';
+ }
+}
diff --git a/src/main/java/examenes/examen20241213/Mamifero.java b/src/main/java/examenes/examen20241213/Mamifero.java
new file mode 100644
index 0000000..bd4e29c
--- /dev/null
+++ b/src/main/java/examenes/examen20241213/Mamifero.java
@@ -0,0 +1,39 @@
+package examenes.examen20241213;
+
+import examenes.examen20241213.utils.Utils;
+
+public class Mamifero extends Animal {
+ private String tipoAlimentacion;
+
+ public Mamifero() {
+ if (Math.random() >= 0.5) {
+ tipoAlimentacion = "Carnívoro";
+ } else {
+ tipoAlimentacion = "Herbívoro";
+ }
+ }
+
+ @Override
+ public float calcularEspacio() {
+ return (getPeso() * 3);
+ }
+
+
+ public String getTipoAlimentacion() {
+ return tipoAlimentacion;
+ }
+
+ public void setTipoAlimentacion(String tipoAlimentacion) {
+ this.tipoAlimentacion = tipoAlimentacion;
+ }
+
+ @Override
+ public String toString() {
+ return "Mamifero{" +
+ "nombre='" + getNombre() + '\'' +
+ ", peso=" + getPeso() +
+ ", tipoAlimentacion='" + tipoAlimentacion + '\'' +
+ ", espacio=" + getEspacio() +
+ '}';
+ }
+}
diff --git a/src/main/java/examenes/examen20241213/Zoologico.java b/src/main/java/examenes/examen20241213/Zoologico.java
new file mode 100644
index 0000000..f4c9d84
--- /dev/null
+++ b/src/main/java/examenes/examen20241213/Zoologico.java
@@ -0,0 +1,92 @@
+package examenes.examen20241213;
+
+import examenes.examen20241213.utils.Utils;
+
+public class Zoologico {
+ public static void main(String[] args) {
+ Animal[] animales = new Animal[Utils.generarIntAleatorioEntreLimites(10, 20)];
+
+ for (int i = 0; i < animales.length; i++) {
+ if (i < animales.length / 2) {
+ animales[i] = new Mamifero();
+ } else {
+ animales[i] = new Ave();
+ }
+ }
+
+ System.out.println("Lista de animales: ");
+ mostrarArrayAnimales(animales);
+
+ System.out.print("\nEspacio total necesario para albergar todos los animales del zoológico: ");
+ float sumaEspacioTotal = 0;
+ for (Animal animal : animales) {
+ sumaEspacioTotal += animal.getEspacio();
+ }
+ System.out.println(sumaEspacioTotal);
+
+
+ System.out.print("\nEspacio total necesario para albergar todos los animales mamíferos del zoológico: ");
+ float sumaEspacioMamiferos = 0;
+ for (Animal animal : animales) {
+ if (animal instanceof Mamifero) sumaEspacioMamiferos += animal.getEspacio();
+ }
+ System.out.println(sumaEspacioMamiferos);
+
+
+ ordenarPorEspacio(animales);
+
+ System.out.println("\nLista de animales ordenados por espacio:");
+ mostrarArrayAnimales(animales);
+
+ System.out.println("\nAnimal que más espacio necesita:");
+ System.out.println(animales[0]);
+
+ System.out.println("\nAnimal que menos espacio necesita:");
+ System.out.println(animales[animales.length - 1]);
+
+ System.out.print("\nTotal de mamíferos Herbívoros: ");
+ int contadorHerbivoros = 0;
+ for (Animal animal : animales) {
+ if (animal instanceof Mamifero &&
+ ((Mamifero) animal).getTipoAlimentacion().equals("Herbívoro")) {
+ contadorHerbivoros++;
+ }
+ }
+ System.out.println(contadorHerbivoros);
+
+
+ System.out.print("\nTotal de aves cuya envergadura es mayor de 100: ");
+ int contadorEnvergadura = 0;
+ for (Animal animal : animales) {
+ if (animal instanceof Ave &&
+ ((Ave) animal).getEnvergaduraAlas() > 100) {
+ contadorEnvergadura++;
+ }
+ }
+ System.out.println(contadorEnvergadura);
+
+
+ }
+
+ private static void ordenarPorEspacio(Animal[] animales) {
+ boolean ordenando;
+ do {
+ ordenando = false;
+ for (int i = 0; i < animales.length; i++) {
+ if (i != (animales.length - 1) && animales[i].getEspacio() < animales[i + 1].getEspacio()) {
+ Animal tempNum = animales[i];
+ animales[i] = animales[i + 1];
+ animales[i + 1] = tempNum;
+ ordenando = true;
+ }
+ }
+ } while (ordenando);
+ }
+
+ private static void mostrarArrayAnimales(Animal[] animales) {
+ for (Animal animal : animales) {
+ System.out.println(animal);
+ }
+ }
+
+}
diff --git a/src/main/java/examenes/examen20241213/utils/Utils.java b/src/main/java/examenes/examen20241213/utils/Utils.java
new file mode 100644
index 0000000..571496b
--- /dev/null
+++ b/src/main/java/examenes/examen20241213/utils/Utils.java
@@ -0,0 +1,12 @@
+package examenes.examen20241213.utils;
+
+public class Utils {
+
+ public static int generarIntAleatorioEntreLimites(int limiteMin, int limiteMax) {
+ return limiteMin + ((int) Math.round(Math.random() * (limiteMax - limiteMin)));
+ }
+
+ public static float generarFloatAleatorioEntreLimites(float limiteMin, float limiteMax) {
+ return limiteMin + (Math.round(Math.random() * (limiteMax - limiteMin)));
+ }
+}