예제 #1
0
파일: Program.cs 프로젝트: sahwar/SoftUni-1
        static void Main(string[] args)
        {
            double[] tokens  = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray();
            Car      car     = new Car(tokens[0], tokens[1], tokens[2]);
            string   command = Console.ReadLine();

            while (command != "END")
            {
                string[] tok = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                switch (tok[0])
                {
                case "Travel": car.Travel(double.Parse(tok[1])); break;

                case "Refuel": car.Refuel(double.Parse(tok[1])); break;

                case "Distance": car.Distance(); break;

                case "Time": car.Time(); break;

                case "Fuel": car.Fuel(); break;
                }

                command = Console.ReadLine();
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            Car      car   = new Car(int.Parse(input[0]), double.Parse(input[1]), double.Parse(input[2]));
            string   line  = Console.ReadLine();

            while (line != "END")
            {
                switch (line.Split()[0].Trim())
                {
                case "Travel":
                    int distance = int.Parse(line.Split()[1]);
                    car.Travel(distance);
                    break;

                case "Refuel":
                    double fuel = double.Parse(line.Split()[1]);
                    car.Refuel(fuel);
                    break;

                case "Distance":
                    Console.WriteLine($"Total distance: {car.Distance():F1} kilometers");
                    break;

                case "Time":
                    Console.WriteLine($"Total time: {car.Time()[0]} hours and {car.Time()[1]} minutes");
                    break;

                case "Fuel":
                    Console.WriteLine($"Fuel left: {car.fuel:F1} liters");
                    break;
                }

                line = Console.ReadLine();
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            string[] carArgs     = Console.ReadLine().Split();
            int      speed       = int.Parse(carArgs[0]);
            int      fuel        = int.Parse(carArgs[1]);
            int      fuelEconomy = int.Parse(carArgs[2]);
            Car      car         = new Car(speed, fuel, fuelEconomy);

            string[] input = Console.ReadLine().Split();

            while (input[0] != "END")
            {
                switch (input[0])
                {
                case "Travel":
                    car.Travel(double.Parse(input[1]));
                    break;

                case "Refuel":
                    car.Refuel(double.Parse(input[1]));
                    break;

                case "Distance":
                    car.Distance();
                    break;

                case "Time":
                    car.Time();
                    break;

                case "Fuel":
                    car.Fuel();
                    break;
                }
                input = Console.ReadLine().Split();
            }
        }