Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. public class TruckDatabase
  10. {
  11. struct Truck
  12. {
  13. public int id;
  14. public float km;
  15. public string type;
  16. public float earnings;
  17. }
  18.  
  19. List<Truck> _trucks = new List<Truck>();
  20.  
  21. public TruckDatabase()
  22. {
  23. Console.WriteLine("Comandos: ");
  24. Console.WriteLine("Agregar id kms tipo ganancia");
  25. Console.WriteLine("Remover id");
  26. Console.WriteLine("Mostrar");
  27. Console.WriteLine("\n");
  28. ReadKey();
  29.  
  30. }
  31.  
  32. void ReadKey()
  33. {
  34. string line = Console.ReadLine();
  35. string[] words = line.Split(' ');
  36. string command = words[0];
  37.  
  38. if (command == "Agregar")
  39. {
  40. if (words.Length > 4)
  41. AddTruck(int.Parse(words[1]), float.Parse(words[2]), words[3], float.Parse(words[4]));
  42. }
  43. else if (command == "Remover")
  44. {
  45. if (words.Length > 1)
  46. RemoveTruck(int.Parse(words[1]));
  47. }
  48. else if (command == "Mostrar")
  49. {
  50. DisplayTrucks();
  51. }
  52. else
  53. {
  54. Console.WriteLine("Comando incorrecto.");
  55. Console.WriteLine("Comandos: ");
  56. Console.WriteLine("Agregar id kms tipo ganancia");
  57. Console.WriteLine("Remover id");
  58. Console.WriteLine("Mostrar");
  59. Console.WriteLine("\n");
  60. }
  61. ReadKey();
  62. }
  63.  
  64.  
  65.  
  66. public void AddTruck(int truckID, float truckKMs, string truckType, float truckEarnings)
  67. {
  68. for (int i = 0; i < _trucks.Count; i++)
  69. if (_trucks[i].id == truckID)
  70. {
  71. Console.WriteLine("Ya existe el camion");
  72. Console.WriteLine("\n");
  73. ReadKey();
  74. }
  75.  
  76. Truck truck = new Truck();
  77. truck.id = truckID;
  78. truck.km = truckKMs;
  79. truck.type = truckType;
  80. truck.earnings = truckEarnings;
  81. if (!_trucks.Contains(truck))
  82. _trucks.Add(truck);
  83.  
  84. Console.WriteLine("Camion Agregado = Id: " + truckID + " / Kms: " + truckKMs + " / Tipo: " + truckType + " / Ganancia: " + truckEarnings);
  85. Console.WriteLine("\n");
  86. ReadKey();
  87. }
  88.  
  89. public void RemoveTruck(int truckId)
  90. {
  91. for (int i = 0; i < _trucks.Count; i++)
  92. if (_trucks[i].id == truckId)
  93. {
  94. _trucks.Remove(_trucks[i]);
  95. Console.WriteLine("Camion Removido = Id: " + truckId);
  96. Console.WriteLine("\n");
  97. ReadKey();
  98. }
  99.  
  100. Console.WriteLine("Camion no existe");
  101. Console.WriteLine("\n");
  102. ReadKey();
  103. }
  104.  
  105. public void DisplayTrucks()
  106. {
  107. foreach (var item in _trucks)
  108. Console.WriteLine("Id: " + item.id + " / Kms: " + item.km + " / Tipo: " + item.type + " / Ganancia: " + item.earnings);
  109.  
  110. Console.WriteLine("\n");
  111.  
  112. if (_trucks.Count == 0)
  113. {
  114. Console.WriteLine("No hay camiones para mostrar");
  115. Console.WriteLine("\n");
  116. }
  117.  
  118. ReadKey();
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement