Skip to content

Commit 7041325

Browse files
Merge branch 'main' of github.com:mouredev/roadmap-retos-programacion into JesusAEE
2 parents 8e402ed + 80d137c commit 7041325

File tree

16 files changed

+2027
-719
lines changed

16 files changed

+2027
-719
lines changed

Roadmap/08 - CLASES/python/sorubadguy.py

Lines changed: 113 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,122 @@
44
"""
55

66
#?Ejemplo de definicion de clase
7-
class Ejemplo:
7+
class Perro:
88

9-
#?atributo de clase
9+
#?Atributo general de la clase
10+
1011

1112
#?Inicializador de la clase
12-
def __init__(self) -> None:
13-
self.hora = time.time_ns()
13+
def __init__(self, nombre: str):
14+
self.nombre = nombre #?Atributo unico para cada instancia
15+
self.trucos = [] #?Si la lista estuviese como atributo general, todas las instancias de esta clase compartirian la misma lista
16+
17+
def agregar_truco(self, truco):
18+
self.trucos.append(truco)
19+
20+
perro1 = Perro("Gero")
21+
perro2 = Perro("Mily")
22+
23+
perro1.agregar_truco("saltar")
24+
perro1.agregar_truco("voltereta")
25+
perro2.agregar_truco("dar la pata")
26+
27+
print(f"{perro1.nombre} puede hacer los siguientes trucos: {perro1.trucos}")
28+
print(f"{perro2.nombre} puede hacer los siguientes trucos: {perro2.trucos}")
29+
30+
#?Herencia, raza tiene las mismas caracteristicas de perro, ademas de las suyas propias
31+
32+
class Raza(Perro):#!Las clases pueden heredar tambien 2 o mas clases base
33+
34+
def __init__(self, nombre: str, color_pelo: str, tipo_pelo: str, altura: float, raza = "puro perro"):
35+
super().__init__(nombre)
36+
self.raza = raza
37+
self.color_pelo = color_pelo
38+
self.tipo_pelo = tipo_pelo
39+
self.altura = altura
40+
41+
def mostrar_raza(self):
42+
print(f"Raza: {self.raza}\nTipo de Pelo: {self.tipo_pelo}\nColor del Pelo: {self.color_pelo}\nAltura: {self.altura} mt(s)")
43+
44+
perro3 = Raza("pancho", "marron", "corto", 1.2)
45+
perro3.agregar_truco("Hacerce el muertito")
46+
perro3.mostrar_raza()
47+
print(perro3.trucos) #?caracteristica de la clase perro, heredada por raza
48+
49+
"""
50+
!Extra
51+
"""
52+
"""
53+
*Clase Pila
54+
"""
55+
class Pila:
56+
57+
def __init__(self, pila = []) -> None:
58+
self.pila = []
59+
if len(pila) == 0:
60+
self.pila = []
61+
else:
62+
for i in range(0, len(pila)):
63+
self.pila.append(pila[i])
64+
65+
66+
def tamano_pila(self):
67+
print(f"La pila posee {len(self.pila)} elementos")
68+
69+
def anadir_elemento(self):
70+
self.pila.append(input("Ingrese el valor a agregar: "))
71+
72+
def quitar_elemento(self):
73+
self.pila.pop()
74+
75+
def mostrar_contenido(self):
76+
elemento = self.pila.pop()
77+
print(elemento)
78+
if(len(self.pila) > 0):
79+
self.mostrar_contenido()
80+
self.pila.append(elemento)
81+
82+
83+
pila = Pila([1,2,3,4,5,6,7,8,9])
84+
pila.tamano_pila()
85+
pila.mostrar_contenido()
86+
#pila.anadir_elemento()
87+
pila.tamano_pila()
88+
pila.mostrar_contenido()
89+
pila.quitar_elemento()
90+
pila.mostrar_contenido()
91+
92+
"""
93+
*Clase Cola
94+
"""
95+
96+
class Cola:
97+
98+
def __init__(self, cola = []) -> None:
99+
self.cola = []
100+
if len(cola) == 0:
101+
self.cola = []
102+
else:
103+
for i in range(0, len(cola)):
104+
self.cola.append(cola[i])
105+
106+
def tamano_cola(self):
107+
print(f"La cola posee {len(self.cola)} elementos")
108+
109+
def anadir_elento(self):
110+
self.cola.append(input("Ingrese el valor a agregar: "))
111+
112+
def quitar_elemento(self):
113+
self.cola.pop(0)
14114

15-
#?Funcion propia de la clase
16-
def mostrar_ejemplo(self):
17-
print("Hola Soy una clase")
115+
def mostrar_contenido(self):
116+
for i in range(0, len(self.cola)):
117+
print(self.cola[i])
18118

19-
def mostrar_hora(self):
20-
print(self.hora)
21119

22-
#!Instancia de una clase
23-
#?Inicializo la instancia
24-
x = Ejemplo()
25-
x.mostrar_hora()
26-
x.mostrar_ejemplo
120+
cola = Cola([1,2,3,4,5,6,7,8,9])
121+
cola.anadir_elento()
122+
cola.tamano_cola()
123+
cola.quitar_elemento()
124+
cola.tamano_cola()
125+
cola.mostrar_contenido()
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
package ejercicio09;
2+
3+
import java.util.ArrayList;
4+
5+
public class AndrewCodev {
6+
public static void main(String[] args) {
7+
Perro perro = new Perro(null, null);
8+
perro.setNombre("Pluto");
9+
perro.setRaza("Labrador");
10+
perro.ladra();
11+
12+
System.out.println(perro.getNombre() + " - " + perro.getRaza() + " - " + perro.ladra());
13+
Gato gato = new Gato(null, null);
14+
gato.setNombre("Tom");
15+
gato.setRaza("Persa");
16+
gato.maulla();
17+
18+
System.out.println(gato.getNombre() + " - " + gato.getRaza() + " - " + gato.maulla());
19+
20+
System.out.println("\n");
21+
22+
// Instancio la clase Gerente
23+
// Gerente gerente = new Gerente(null, null, null);
24+
ArrayList<Gerente> gerentes = new ArrayList<>();
25+
gerentes.add(new Gerente(1L, "Andres", "Desarrollo"));
26+
gerentes.add(new Gerente(2L, "Laura", "Diseño Gráfico"));
27+
gerentes.add(new Gerente(3L, "Luis", "Contabilidad"));
28+
Gerente.listarGerentes(gerentes);
29+
30+
ArrayList<GerenteDeProyecto> gerentePro = new ArrayList<>();
31+
gerentePro.add(new GerenteDeProyecto(1L, "Diego", "Curso Java Web"));
32+
gerentePro.add(new GerenteDeProyecto(2L, "Ana", "Diseño de interfeces de usuario"));
33+
gerentePro.add(new GerenteDeProyecto(3L, "Sara", "Automatización Nómina"));
34+
GerenteDeProyecto.listarGerentesProyecto(gerentePro);
35+
36+
ArrayList<Programador> programadorer = new ArrayList<>();
37+
programadorer.add(new Programador(1L, "Julio Cesar", "Roma"));
38+
programadorer.add(new Programador(2L, "Alejandro","Grecia"));
39+
programadorer.add(new Programador(3L, "Willian", "Escocia"));
40+
Programador.listarProgramadores(programadorer);
41+
}
42+
}
43+
44+
//Se crea la superclase Animal
45+
class Animal {
46+
private String nombre;
47+
private String raza;
48+
49+
public Animal(String nombre, String raza) {
50+
super();
51+
this.nombre = nombre;
52+
this.raza = raza;
53+
}
54+
55+
public String getNombre() {
56+
return nombre;
57+
}
58+
59+
public void setNombre(String nombre) {
60+
this.nombre = nombre;
61+
}
62+
63+
public String getRaza() {
64+
return raza;
65+
}
66+
67+
public void setRaza(String raza) {
68+
this.raza = raza;
69+
}
70+
}
71+
72+
//Se crea la clase perro que hereda de la Clase Animal
73+
class Perro extends Animal {
74+
75+
public Perro(String nombre, String raza) {
76+
super(nombre, raza);
77+
}
78+
79+
public String ladra() {
80+
return "guau, guau";
81+
}
82+
}
83+
84+
//Se crea la clase Gato que hereda de la Clase Animal
85+
class Gato extends Animal {
86+
public Gato(String nombre, String raza) {
87+
super(nombre, raza);
88+
}
89+
90+
public String maulla() {
91+
return "miau, miau";
92+
}
93+
}
94+
95+
//DIFICULTAD EXTRA
96+
97+
class Empleado {
98+
private Long idEmpleado;
99+
private String nombre;
100+
101+
public Empleado(Long idEmpleado, String nombre) {
102+
super();
103+
this.idEmpleado = idEmpleado;
104+
this.nombre = nombre;
105+
}
106+
107+
public Long getIdEmpleado() {
108+
return idEmpleado;
109+
}
110+
111+
public void setIdEmpleado(Long idEmpleado) {
112+
this.idEmpleado = idEmpleado;
113+
}
114+
115+
public String getNombre() {
116+
return nombre;
117+
}
118+
119+
public void setNombre(String nombre) {
120+
this.nombre = nombre;
121+
}
122+
}
123+
124+
class Gerente extends Empleado {
125+
String area;
126+
127+
public Gerente(Long idEmpleado, String nombre, String area) {
128+
super(idEmpleado, nombre);
129+
this.area = area;
130+
}
131+
132+
public String getArea() {
133+
return area;
134+
}
135+
136+
public void setArea(String area) {
137+
this.area = area;
138+
}
139+
140+
public static void listarGerentes(ArrayList<Gerente> gerentes) {
141+
System.out.println("\nLISTA DE GERENTES DE LA EMPRESA");
142+
for (int i = 0; i < gerentes.size(); i++) {
143+
System.out.println("Área: " + gerentes.get(i).getArea() + " | Gerente: " + gerentes.get(i).getNombre());
144+
}
145+
}
146+
147+
public static void contratarEmpleados() {
148+
System.out.println("Vas a contratar un nuevo empleado");
149+
}
150+
151+
public static void nuevoProyecto() {
152+
System.out.println("Creando nuevo proyecto");
153+
}
154+
}
155+
156+
class GerenteDeProyecto extends Empleado {
157+
String proyecto;
158+
159+
public GerenteDeProyecto(Long idEmpleado, String nombre, String proyecto) {
160+
super(idEmpleado, nombre);
161+
this.proyecto = proyecto;
162+
}
163+
164+
public String getProyecto() {
165+
return proyecto;
166+
}
167+
168+
public void setProyecto(String proyecto) {
169+
this.proyecto = proyecto;
170+
}
171+
172+
public static void listarGerentesProyecto(ArrayList<GerenteDeProyecto> gerentePro) {
173+
System.out.println("\nLISTA DE GERENTES DE PROYECTOS");
174+
for (int i = 0; i < gerentePro.size(); i++) {
175+
System.out.println(
176+
"Proyecto: " + gerentePro.get(i).getProyecto() + " | Gerente: " + gerentePro.get(i).getNombre());
177+
}
178+
}
179+
180+
public static void asignarDesarrollador() {
181+
System.out.println("Asignando nuevo desarrollador al equipo y proyecto");
182+
}
183+
}
184+
185+
class Programador extends Empleado {
186+
String equipoDeTrabajo;
187+
188+
public Programador(Long idEmpleado, String nombre, String equipoDeTrabajo) {
189+
super(idEmpleado, nombre);
190+
this.equipoDeTrabajo = equipoDeTrabajo;
191+
}
192+
193+
public String getEquipoDeTrabajo() {
194+
return equipoDeTrabajo;
195+
}
196+
197+
public void setEquipoDeTrabajo(String equipoDeTrabajo) {
198+
this.equipoDeTrabajo = equipoDeTrabajo;
199+
}
200+
201+
public static void listarProgramadores(ArrayList<Programador> programadores) {
202+
System.out.println("\nLISTA DE PROGRAMADORES");
203+
for (int i = 0; i < programadores.size(); i++) {
204+
System.out.println("Equipo de trabajo: " + programadores.get(i).getEquipoDeTrabajo() + " | Programador: "
205+
+ programadores.get(i).getNombre());
206+
}
207+
}
208+
209+
public static void desarrollarAplicacion() {
210+
System.out.println("Iniciando el desarrollo de la app para el equipo");
211+
}
212+
}

0 commit comments

Comments
 (0)