forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mouredev#6063 from JesusAntonioEEscamilla/JesusAEE
09 - Java & Python
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
|
||
/** #09 - Java -> Jesus Antonio Escamilla */ | ||
|
||
public class JesusAntonioEEscamilla { | ||
public static void main(String[] args) { | ||
//---EJERCIÓ--- | ||
Animal perro = new Perro(); | ||
Animal gato = new Gato(); | ||
Animal pajaro = new Pajaro(); | ||
|
||
System.out.println("Herencia"); | ||
imprimirSonido(perro); | ||
imprimirSonido(gato); | ||
imprimirSonido(pajaro); | ||
|
||
System.out.println("\n"); | ||
|
||
System.out.println("Extra Métodos"); | ||
// Extra: Mostrar acciones adicionales | ||
((Perro) perro).correr(); | ||
((Gato) gato).cazar(); | ||
((Pajaro) pajaro).volar(); | ||
//---EXTRA--- | ||
// Pendiente | ||
} | ||
|
||
//---EJERCIÓ--- | ||
// Superclase Animal | ||
static class Animal { | ||
public void hacerSonido(){ | ||
System.out.println("El animal hace ruido"); | ||
} | ||
} | ||
|
||
// Subclases Perro | ||
static class Perro extends Animal { | ||
@Override | ||
public void hacerSonido(){ | ||
System.out.println("El perro ladra: ¡Guau Guau!"); | ||
} | ||
|
||
// Método adicional para perro | ||
public void correr(){ | ||
System.out.println("Esta corriendo felizmente"); | ||
} | ||
} | ||
|
||
// Subclases Gato | ||
static class Gato extends Animal { | ||
@Override | ||
public void hacerSonido(){ | ||
System.out.println("El gato maúlla: ¡Miau Miau!"); | ||
} | ||
|
||
// Método adicional para gato | ||
public void cazar(){ | ||
System.out.println("Esta cazando un ratón"); | ||
} | ||
} | ||
|
||
// Nueva Subclases Pájaro | ||
static class Pajaro extends Animal { | ||
@Override | ||
public void hacerSonido(){ | ||
System.out.println("El pájaro canta: ¡Pio Pio!"); | ||
} | ||
|
||
// Método adicional para gato | ||
public void volar(){ | ||
System.out.println("Esta volando alto en el cielo"); | ||
} | ||
} | ||
|
||
// Función que recibe un objeto de tipo Animal y llama a su método hacerSonido | ||
public static void imprimirSonido(Animal animal){ | ||
animal.hacerSonido(); | ||
} | ||
|
||
|
||
|
||
/**-----DIFICULTAD EXTRA-----*/ | ||
|
||
// Pendientes | ||
|
||
/**-----DIFICULTAD EXTRA-----*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# #09 - Python -> Jesus Antonio Escamilla | ||
|
||
""" | ||
EJERCIÓ | ||
""" | ||
# Definimos la superclase Animal | ||
class Animal: | ||
def hacer_sonido(self): | ||
raise NotImplemented("Este método debe ser implementado por las subclases") | ||
|
||
# Definimos la subclase Perro | ||
class Perro(Animal): | ||
def hacer_sonido(self): | ||
return "El perro dice: ¡Guau Guau!" | ||
|
||
# Definimos la subclase Gato | ||
class Gato(Animal): | ||
def hacer_sonido(self): | ||
return "El gato dice: ¡Miau Miau!" | ||
|
||
# Definimos la subclase Pájaro | ||
class Pajaro(Animal): | ||
def hacer_sonido(self): | ||
return "El pájaro dice: ¡Pio Pio!" | ||
|
||
# Función para imprimir el sonido de cualquier animal | ||
def imprimir_sonido(animal): | ||
print(f"{animal.hacer_sonido()}") | ||
|
||
# Crear instancias | ||
perro = Perro() | ||
gato = Gato() | ||
pajaro = Pajaro() | ||
|
||
imprimir_sonido(perro) | ||
imprimir_sonido(gato) | ||
imprimir_sonido(pajaro) | ||
|
||
|
||
|
||
""" | ||
EXTRA | ||
""" | ||
# Pendientes |