Skip to content

Instantly share code, notes, and snippets.

@pablovillacanas
Last active June 15, 2018 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablovillacanas/52748876c01ae1ee62c093a2e10cb484 to your computer and use it in GitHub Desktop.
Save pablovillacanas/52748876c01ae1ee62c093a2e10cb484 to your computer and use it in GitHub Desktop.
class Comida {
public Comida() {
}
public double getPrecio() {
return 0;
}
}
//Ingredientes
class Pasta extends Comida{
Comida com;
public Pasta(Comida com) {
this.com = com;
}
public double getPrecio() {
return 0.5 + com.getPrecio();
}
}
class SalsaTomate extends Comida{
Comida com;
public SalsaTomate(Comida com) {
this.com = com;
}
public double getPrecio() {
return 1 + com.getPrecio();
}
}
class Carne extends Comida{
Comida com;
public Carne(Comida com) {
this.com = com;
}
public double getPrecio() {
return 2 + com.getPrecio();
}
}
// Fin Ingredientes
public class Main {
public static void main(String... args) {
Comida comida = new Comida();
Pasta pasta = new Pasta(comida);
SalsaTomate salsa = new SalsaTomate(pasta);
Carne carne = new Carne(salsa);
System.out.println(carne.getPrecio());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment