Guest User

Untitled

a guest
Apr 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. public class Program
  2. {
  3. public static void Main(string[] args)
  4. {
  5.  
  6. Console.WriteLine("Bienvenido al Mundo de Changos");
  7. Chango chang1 = new Chango();
  8. Banana ban1 = new Banana("Grande","Dulce");
  9. chang1.Eat(ban1);
  10.  
  11. Chango chang2 = new Chango();
  12. Limon lim1 = new Limon("pequeña","acida");
  13. chang2.Eat(lim1);
  14.  
  15. }
  16. }
  17. /////// Tipo de alimento
  18. class Fruta
  19. {
  20. private string fsize;
  21. public string size
  22. {
  23. get { return fsize;}
  24. set { fsize = value;}
  25. }
  26.  
  27. private string fflavor;
  28. public string flavor
  29. {
  30. get { return fflavor;}
  31. set { fflavor = flavor;}
  32. }
  33. public Fruta(string size, string flavor)
  34. {
  35. this.size = size;
  36. this.flavor = flavor;
  37. }
  38.  
  39. }
  40. ////////// Frutas
  41. class Banana : Fruta
  42. {
  43. public Banana(string size, string flavor ):base(size, flavor)
  44. {
  45.  
  46. }
  47. }
  48.  
  49. class Limon : Fruta
  50. {
  51. public Limon(string size, string flavor):base(size,flavor)
  52. {
  53.  
  54. }
  55. }
  56.  
  57. /////// El Chango
  58. class Chango
  59. {
  60.  
  61. public void Sad(Fruta fruta){
  62. Console.WriteLine ("El changuito esta triste porque no le gusta " + fruta.GetType()) ;
  63. }
  64.  
  65. public void Happy(Fruta fruta){
  66. Console.WriteLine ("El changuito esta contento porque le gusta la " + fruta.GetType()) ;
  67. }
  68.  
  69. public void Taste (Fruta fruta){
  70. Console.WriteLine("El changuito cree que la " + fruta.GetType() + " sabe " +fruta.flavor);
  71. }
  72.  
  73.  
  74. public void Eat(Fruta fruta){
  75. Console.WriteLine("El changuito comió " + fruta.GetType().ToString() );
  76. if(fruta.GetType() == Type.GetType("Rextester.Banana"))
  77. {
  78. Happy(fruta);
  79. } else {
  80. Sad(fruta);
  81. }
  82. Taste(fruta);
  83. }
  84. }
Add Comment
Please, Sign In to add comment