Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.9 kB
4
Indexable
using System;
using System.Collections.Generic;
using System.Linq;

namespace task
{

    abstract class Vehicle
    {
        public double  weight;

        public Vehicle(double _weight)
        {
            weight = _weight;
        }


    }

    class Car : Vehicle
    {

        public int passengerCount;

        public Car(double _weight, int _passengerCount) : base(_weight)
        {
            passengerCount = _passengerCount;
        }


    }

    class Truck : Vehicle
    {

        public double cargoWeight;

        public Truck(double _weight, double _cargoWeight) : base(_weight)
        {
            cargoWeight = _cargoWeight;
        }
    }

    class Motorcycle : Vehicle
    {

        public double hasSideCar;

        public Motorcycle(double _weight, int _hasSideCar) : base(_weight)
        {
            hasSideCar = _hasSideCar;
        }
    }



    class Program
    {
        static void Main(string[] args)
        {
           
            int n = int.Parse(Console.ReadLine());
            List<Vehicle> vehicles = new List<Vehicle>();
            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine();
                string[] data = input.Split(',');
                if (data[0] == "1")
                {
                    var vehicle = new Car(double.Parse(data[1]), int.Parse(data[2]));
                  
                   vehicles.Add(vehicle);
                }
                else if (data[0] == "2")
                {
                    var vehicle = new Truck(double.Parse(data[1]), double.Parse(data[2]));

                    vehicles.Add(vehicle);
                }
                else if (data[0] == "3")
                {
                    var vehicle = new Motorcycle(double.Parse(data[1]), int.Parse(data[2]));

                    vehicles.Add(vehicle);
                }
            }
        
            double carWeight = 0;
            double truckWeight = 0;
            double motorcycleWeight = 0;

            vehicles.ForEach(v =>
            {
                if (v is Car)
                {
                    carWeight += v.weight;
                } else if (v is Truck)
                {
                    truckWeight += v.weight;
                } else if (v is Motorcycle)
                {
                    motorcycleWeight += v.weight;
                }
            });

            Console.WriteLine("Car: Total Weight - {0}", carWeight);
            Console.WriteLine("Truck: Total Weight - {0}", truckWeight);
            Console.WriteLine("Motorcycle: Total Weight - {0}", motorcycleWeight);

            Console.WriteLine("Total Cars: {0}", vehicles.Where(v => v is Car).Count());
            Console.WriteLine("Total Trucks: {0}", vehicles.Where(v => v is Truck).Count());
            Console.WriteLine("Total Motorcycles: {0}", vehicles.Where(v => v is Motorcycle).Count());
           

        }
    }
}