Examen 2024/12/13
This commit is contained in:
54
.idea/workspace.xml
generated
54
.idea/workspace.xml
generated
@@ -4,12 +4,12 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e2c4f742-461e-4c7a-a6e0-b5f4b8e8f229" name="Changes" comment="Se formatea utils">
|
<list default="true" id="e2c4f742-461e-4c7a-a6e0-b5f4b8e8f229" name="Changes" comment="Examen 2024/12/13">
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241122/Ejercicio_a.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241213/Animal.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241122/Ejercicio_b.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241213/Ave.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241122/Ejercicio_c.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241213/Mamifero.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241122/Ejercicio_d.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241213/Zoologico.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241122/Utils/Utils.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20241213/utils/Utils.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@@ -38,22 +38,24 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"Application.Ejercicio_a.executor": "Run",
|
"Application.Ejercicio_a.executor": "Run",
|
||||||
"Application.Ejercicio_b.executor": "Run",
|
"Application.Ejercicio_b.executor": "Run",
|
||||||
"Application.Ejercicio_c.executor": "Run",
|
"Application.Ejercicio_c.executor": "Run",
|
||||||
"Application.Ejercicio_d.executor": "Run",
|
"Application.Ejercicio_d.executor": "Run",
|
||||||
"Application.Ejercicio_e.executor": "Run",
|
"Application.Ejercicio_e.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"Application.Zoologico.executor": "Run",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "main",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"kotlin-language-version-configured": "true",
|
"git-widget-placeholder": "main",
|
||||||
"onboarding.tips.debug.path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/net/h4ckx0r/Main.java"
|
"kotlin-language-version-configured": "true",
|
||||||
|
"onboarding.tips.debug.path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/net/h4ckx0r/Main.java"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="CopyClassDialog.RECENTS_KEY">
|
<key name="CopyClassDialog.RECENTS_KEY">
|
||||||
|
<recent name="examenes.examen20241213" />
|
||||||
<recent name="examenes.examen20241122" />
|
<recent name="examenes.examen20241122" />
|
||||||
<recent name="examenes.examen20241025" />
|
<recent name="examenes.examen20241025" />
|
||||||
</key>
|
</key>
|
||||||
@@ -147,7 +149,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1729857949405</updated>
|
<updated>1729857949405</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="11" />
|
<task id="LOCAL-00011" summary="Examen 2024/11/21">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1732277745346</created>
|
||||||
|
<option name="number" value="00011" />
|
||||||
|
<option name="presentableId" value="LOCAL-00011" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1732277745346</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="12" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
@@ -172,6 +182,8 @@
|
|||||||
<MESSAGE value="Ejercicio A terminado" />
|
<MESSAGE value="Ejercicio A terminado" />
|
||||||
<MESSAGE value="utils y resto" />
|
<MESSAGE value="utils y resto" />
|
||||||
<MESSAGE value="Se formatea utils" />
|
<MESSAGE value="Se formatea utils" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Se formatea utils" />
|
<MESSAGE value="Examen 2024/11/21" />
|
||||||
|
<MESSAGE value="Examen 2024/12/13" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Examen 2024/12/13" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
52
src/main/java/examenes/examen20241213/Animal.java
Normal file
52
src/main/java/examenes/examen20241213/Animal.java
Normal file
@@ -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 +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/main/java/examenes/examen20241213/Ave.java
Normal file
33
src/main/java/examenes/examen20241213/Ave.java
Normal file
@@ -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() +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/main/java/examenes/examen20241213/Mamifero.java
Normal file
39
src/main/java/examenes/examen20241213/Mamifero.java
Normal file
@@ -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() +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
92
src/main/java/examenes/examen20241213/Zoologico.java
Normal file
92
src/main/java/examenes/examen20241213/Zoologico.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
12
src/main/java/examenes/examen20241213/utils/Utils.java
Normal file
12
src/main/java/examenes/examen20241213/utils/Utils.java
Normal file
@@ -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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user