Ejemplo n.º 1
0
        static void Main()
        {
            double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray();
            Car car= new Car(input[0], input[1], input[2]);
            string command = Console.ReadLine();

            while (!command.Equals("END"))
            {
                string[] com = command.Split();

                switch (com[0])
                {
                    case "Travel": car.Travel(double.Parse(com[1]));
                        break;
                    case "Distance":
                    {
                        Console.WriteLine("Total distance: {0:F1} kilometers", car.Distance);

                    }
                        break;
                    case "Refuel":
                        car.Refuel(double.Parse(com[1]));
                         break;
                    case "Time":
                        Console.WriteLine($"Total time: {car.getTime()}");
                        break;
                    case "Fuel":
                        Console.WriteLine("Fuel left: {0:f1} liters",car.fuel);
                        break;
                }

                command = Console.ReadLine();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // First line
            var carSpecs = Console.ReadLine()
                .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            // Init car
            var car = new Car(carSpecs[0], carSpecs[1], carSpecs[2]);

            // Main Loop
            while (true)
            {
                var command = Console.ReadLine()
                    .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                if (command.First() == "END") break;

                switch (command.First())
                {
                    case "Travel":
                        car.Travel(command[1]);
                        break;
                    case "Refuel":
                        car.Refuel(command[1]);
                        break;
                    case "Distance":
                        Console.WriteLine(car.Distance);
                        break;
                    case "Time":
                        Console.WriteLine(car.Time);
                        break;
                    case "Fuel":
                        Console.WriteLine(car.FuelLeft);
                        break;
                }
            }
        }