1_9tdiMamkaMu

StartUp

Apr 21st, 2021 (edited)
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2.  
  3. using Vehicles.Models;
  4.  
  5. namespace Vehicles
  6. {
  7.     public class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] carInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  12.             string[] truckInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  13.             string[] busInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  14.  
  15.             Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3]));
  16.             Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3]));
  17.             Vehicle bus = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3]));
  18.  
  19.             int n = int.Parse(Console.ReadLine());
  20.  
  21.             Vehicle vehicle;
  22.  
  23.             for (int i = 0; i < n; i++)
  24.             {
  25.                 string[] info = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  26.  
  27.                 if (info[1].ToLower() == "car")
  28.                 {
  29.                     vehicle = car;
  30.                 }
  31.                 else if (info[1].ToLower() == "truck")
  32.                 {
  33.                     vehicle = truck;
  34.                 }
  35.                 else
  36.                 {
  37.                     vehicle = bus;
  38.                 }
  39.  
  40.                 string command = info[0];
  41.  
  42.                 try
  43.                 {
  44.                     if (command.ToLower() == "drive")
  45.                     {
  46.                         vehicle.Drive(double.Parse(info[2]));
  47.                     }
  48.                     else if (command.ToLower() == "driveempty")
  49.                     {
  50.                         Bus currentBuss = vehicle as Bus;
  51.                         currentBuss.DriveEmpty(double.Parse(info[2]));
  52.                     }
  53.                     else
  54.                     {
  55.                         vehicle.ReFuel(double.Parse(info[2]));
  56.                     }            
  57.                 }
  58.                 catch (Exception ex)
  59.                 {
  60.                     Console.WriteLine(ex.Message);
  61.                 }
  62.             }
  63.             Console.WriteLine(car);
  64.             Console.WriteLine(truck);
  65.             Console.WriteLine(bus);
  66.         }
  67.     }
  68. }
  69.  
Add Comment
Please, Sign In to add comment