-
-
Save pablovillacanas/52748876c01ae1ee62c093a2e10cb484 to your computer and use it in GitHub Desktop.
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
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