Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public class TruckDatabase
- {
- struct Truck
- {
- public int id;
- public float km;
- public string type;
- public float earnings;
- }
- List<Truck> _trucks = new List<Truck>();
- public TruckDatabase()
- {
- Console.WriteLine("Comandos: ");
- Console.WriteLine("Agregar id kms tipo ganancia");
- Console.WriteLine("Remover id");
- Console.WriteLine("Mostrar");
- Console.WriteLine("\n");
- ReadKey();
- }
- void ReadKey()
- {
- string line = Console.ReadLine();
- string[] words = line.Split(' ');
- string command = words[0];
- if (command == "Agregar")
- {
- if (words.Length > 4)
- AddTruck(int.Parse(words[1]), float.Parse(words[2]), words[3], float.Parse(words[4]));
- }
- else if (command == "Remover")
- {
- if (words.Length > 1)
- RemoveTruck(int.Parse(words[1]));
- }
- else if (command == "Mostrar")
- {
- DisplayTrucks();
- }
- else
- {
- Console.WriteLine("Comando incorrecto.");
- Console.WriteLine("Comandos: ");
- Console.WriteLine("Agregar id kms tipo ganancia");
- Console.WriteLine("Remover id");
- Console.WriteLine("Mostrar");
- Console.WriteLine("\n");
- }
- ReadKey();
- }
- public void AddTruck(int truckID, float truckKMs, string truckType, float truckEarnings)
- {
- for (int i = 0; i < _trucks.Count; i++)
- if (_trucks[i].id == truckID)
- {
- Console.WriteLine("Ya existe el camion");
- Console.WriteLine("\n");
- ReadKey();
- }
- Truck truck = new Truck();
- truck.id = truckID;
- truck.km = truckKMs;
- truck.type = truckType;
- truck.earnings = truckEarnings;
- if (!_trucks.Contains(truck))
- _trucks.Add(truck);
- Console.WriteLine("Camion Agregado = Id: " + truckID + " / Kms: " + truckKMs + " / Tipo: " + truckType + " / Ganancia: " + truckEarnings);
- Console.WriteLine("\n");
- ReadKey();
- }
- public void RemoveTruck(int truckId)
- {
- for (int i = 0; i < _trucks.Count; i++)
- if (_trucks[i].id == truckId)
- {
- _trucks.Remove(_trucks[i]);
- Console.WriteLine("Camion Removido = Id: " + truckId);
- Console.WriteLine("\n");
- ReadKey();
- }
- Console.WriteLine("Camion no existe");
- Console.WriteLine("\n");
- ReadKey();
- }
- public void DisplayTrucks()
- {
- foreach (var item in _trucks)
- Console.WriteLine("Id: " + item.id + " / Kms: " + item.km + " / Tipo: " + item.type + " / Ganancia: " + item.earnings);
- Console.WriteLine("\n");
- if (_trucks.Count == 0)
- {
- Console.WriteLine("No hay camiones para mostrar");
- Console.WriteLine("\n");
- }
- ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement