Last active
October 11, 2021 22:51
-
-
Save j2deme/5ee5fe37378fc0e542673335c71b462e to your computer and use it in GitHub Desktop.
POO - Osos Escandalosos
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
package com.j2deme; | |
public class Ingrediente { | |
private String nombre; | |
private String sabor; | |
private boolean aportaOlor; | |
private boolean aportaTextura; | |
private boolean aportaColor; | |
public Ingrediente(){ | |
this.setAportaOlor(true); | |
this.setAportaTextura(true); | |
this.setAportaColor(false); | |
} | |
public Ingrediente(String nombre, String sabor){ | |
this.setNombre(nombre); | |
this.setSabor(sabor); | |
this.setAportaOlor(true); | |
this.setAportaTextura(true); | |
this.setAportaColor(false); | |
} | |
public String getNombre() { | |
return nombre; | |
} | |
public void setNombre(String nombre) { | |
this.nombre = nombre; | |
} | |
public String getSabor() { | |
return sabor; | |
} | |
public void setSabor(String sabor) { | |
this.sabor = sabor; | |
} | |
public boolean isAportaOlor() { | |
return aportaOlor; | |
} | |
public void setAportaOlor(boolean aportaOlor) { | |
this.aportaOlor = aportaOlor; | |
} | |
public boolean isAportaTextura() { | |
return aportaTextura; | |
} | |
public void setAportaTextura(boolean aportaTextura) { | |
this.aportaTextura = aportaTextura; | |
} | |
public boolean isAportaColor() { | |
return aportaColor; | |
} | |
public void setAportaColor(boolean aportaColor) { | |
this.aportaColor = aportaColor; | |
} | |
} |
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
package com.j2deme; //El nombre del paquete puede variar según el usuario que lo desarrolla | |
public class Main { | |
public static void main(String[] args) { | |
int edad = 34; | |
OsoPardo teddy = new OsoPardo(true); // Instanciación | |
teddy.setColor("Azul"); | |
System.out.println(teddy.getColor()); | |
//teddy.setEsHiperactivo(true); | |
if(teddy.esHiperactivo()){ | |
System.out.println("Teddy esta loco!"); | |
} | |
teddy.dormir(20); | |
teddy.nadar(); | |
//System.out.println(teddy); | |
System.out.println("=========="); | |
OsoPolar bolo = new OsoPolar(); | |
bolo.setColor("Blanco"); | |
bolo.setComeFruta(true); | |
Ingrediente pan = new Ingrediente(); | |
pan.setNombre("Pan blanco"); | |
pan.setSabor("umami"); | |
Ingrediente jamon = new Ingrediente("Jamón","salado"); | |
Ingrediente aguacate = new Ingrediente("Aguacate","ácido"); | |
Ingrediente tomate = new Ingrediente("Tomate","ácido"); | |
bolo.cocinar(pan, jamon, aguacate); | |
bolo.cocinar(pan, jamon, tomate); | |
Ingrediente lechuga = new Ingrediente("Lechuga","umami"); | |
bolo.cocinar(lechuga, aguacate, tomate); | |
} | |
} |
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
package com.j2deme; | |
public class Oso { | |
private String color; | |
private boolean comeFruta = false; | |
private String tipo; | |
public void comer(){} | |
public void nadar(int distancia){}// = 10 | |
public void nadar(){ | |
this.nadar(10); | |
} | |
public void dormir(int tiempo, boolean hibernar){}//=false | |
public void dormir(int tiempo){ | |
this.dormir(tiempo, false); | |
} | |
public String getColor() { | |
return color; | |
} | |
public void setColor(String color) { | |
this.color = color; | |
} | |
public boolean comeFruta() { | |
return comeFruta; | |
} | |
public void setComeFruta(boolean comeFruta) { | |
this.comeFruta = comeFruta; | |
} | |
public String getTipo() { | |
return tipo; | |
} | |
public void setTipo(String tipo) { | |
this.tipo = tipo; | |
} | |
} |
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
package com.j2deme; | |
public class OsoPanda extends Oso { | |
public boolean esOtaku = true; | |
public String color2 = "Negro"; | |
public int tomarSelfie(String fecha, String lugar){ | |
return 10; | |
} | |
public int tomarSelfie(String fecha, String lugar, Platillo comida){ | |
System.out.println("Cheese!!"); | |
System.out.printf("Me encanta el %s\n", comida.getIngredientes(). | |
get(1).getNombre()); | |
return 99; | |
} | |
} |
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
package com.j2deme; | |
public class OsoPardo extends Oso { | |
private boolean esHiperactivo = false; | |
public OsoPardo(boolean esHiperactivo) { | |
this.esHiperactivo = esHiperactivo; | |
} | |
public void sociabilizar(){} | |
public void setEsHiperactivo(boolean esHiperactivo){ | |
this.esHiperactivo = esHiperactivo; | |
} | |
public boolean esHiperactivo(){ | |
return esHiperactivo; | |
} | |
} |
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
package com.j2deme; | |
public class OsoPolar extends Oso { | |
public boolean esCallado = true; | |
public void cocinar(Ingrediente ingrediente1, Ingrediente ingrediente2, | |
Ingrediente ingrediente3){ | |
Platillo comida = new Platillo(); | |
comida.agregarIngrediente(ingrediente1); | |
comida.agregarIngrediente(ingrediente2); | |
comida.agregarIngrediente(ingrediente3); | |
System.out.println(comida.verPlatillo()); | |
OsoPanda pandaTemporal = new OsoPanda(); | |
pandaTemporal.tomarSelfie("Hoy", "Aquí", comida); | |
} | |
} |
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
package com.j2deme; | |
import java.util.Vector; | |
public class Platillo { | |
private Vector<Ingrediente> ingredientes = new Vector<>(); | |
public Vector<Ingrediente> getIngredientes() { | |
return ingredientes; | |
} | |
/** | |
* Añade un ingrediente a la vez | |
* | |
* @param ingrediente | |
*/ | |
public void agregarIngrediente(Ingrediente ingrediente) { | |
this.ingredientes.add(ingrediente); | |
} | |
public String verPlatillo(){ | |
String descripcion = "El platillo tiene "; | |
for (int i = 0; i < ingredientes.size(); i++) { | |
descripcion = descripcion.concat(ingredientes.get(i).getNombre() + ","); | |
} | |
descripcion = descripcion.concat("."); | |
return descripcion; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment