fork download
  1. // POO con menos if's (c) 2024 Baltasar <baltasarq@gmail.com> MIT License
  2.  
  3. using System;
  4. using System.Text;
  5. using System.Collections.Generic;
  6.  
  7.  
  8. class POI {
  9. public /*required*/ string Name { get; init; }
  10. public /*required*/ double Lat { get; init; }
  11. public /*required*/ double Lon { get; init; }
  12.  
  13. public override string ToString()
  14. {
  15. return $"{this.Name}: W{this.Lon}º N{this.Lat}º";
  16. }
  17. }
  18.  
  19. class City: POI {
  20. public override string ToString()
  21. {
  22. return "Ciudad de " + base.ToString();
  23. }
  24. }
  25.  
  26. class Monument: POI {
  27. public override string ToString()
  28. {
  29. return "Monumento de " + base.ToString();
  30. }
  31. }
  32.  
  33. class Mountain: POI {
  34. public override string ToString()
  35. {
  36. return "Cima del " + base.ToString();
  37. }
  38. }
  39.  
  40. class Lake: POI {
  41. public override string ToString()
  42. {
  43. return "Lago " + base.ToString();
  44. }
  45. }
  46.  
  47. class Reporter {
  48. public Reporter(IEnumerable<POI> lpois)
  49. {
  50. this.lpois = new List<POI>( lpois );
  51. }
  52.  
  53. public IList<POI> LPOIS => new List<POI>( this.lpois );
  54.  
  55. public string Report()
  56. {
  57. var toret = new StringBuilder();
  58.  
  59. foreach(var poi in this.lpois) {
  60. toret.AppendLine( poi.ToString() );
  61. }
  62.  
  63. return toret.ToString();
  64. }
  65.  
  66. private List<POI> lpois;
  67. }
  68.  
  69. public class Test
  70. {
  71. public static void Main()
  72. {
  73. var l1 = new List<POI> {
  74. new City { Name = "El Cabo",
  75. Lat = -34.0558188,
  76. Lon = 18.3003856 },
  77. new Mountain { Name = "Everest",
  78. Lat = 27.9881186,
  79. Lon = 86.9043755 },
  80. new Monument { Name = "Torre Eiffel",
  81. Lat = 48.8583,
  82. Lon = -2.2945 },
  83. new Lake { Name = "Español",
  84. Lat = 43.6150755,
  85. Lon = 173.1834932 },
  86. };
  87.  
  88. Console.WriteLine( new Reporter( l1 ).Report() );
  89. }
  90. }
  91.  
Success #stdin #stdout 0.06s 28892KB
stdin
Standard input is empty
stdout
Ciudad de El Cabo: W18.3003856º N-34.0558188º
Cima del Everest: W86.9043755º N27.9881186º
Monumento de Torre Eiffel: W-2.2945º N48.8583º
Lago Español: W173.1834932º N43.6150755º