daily pastebin goal
25%
SHARE
TWEET

Untitled

Chessmaster Nov 9th, 2018 84 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. using System;
  2. using System.Globalization;
  3. using System.Numerics;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. class Program
  8. {
  9.     static void Main()
  10.     {
  11.         List<Vehicle> vehicles = new List<Vehicle>();
  12.  
  13.         int carsCounter = 0;
  14.         int trucksCounter = 0;
  15.         double averageCarsHP = 0;
  16.         double averageTruckHP = 0;
  17.  
  18.         while (true)
  19.         {
  20.             string[] tokens = Console.ReadLine().Split();
  21.  
  22.             if (tokens[0] == "End")
  23.             {
  24.                 break;
  25.             }
  26.  
  27.             string type = tokens[0];
  28.             string model = tokens[1];
  29.             string color = tokens[2];
  30.             double horsePower = double.Parse(tokens[3]);
  31.  
  32.             if (type.ToLower() == "car")
  33.             {
  34.                 carsCounter++;
  35.                 averageCarsHP += horsePower;
  36.  
  37.                 Vehicle vehicle = new Vehicle("Car", model, color, horsePower);
  38.                 vehicles.Add(vehicle);
  39.             }
  40.             else
  41.             {
  42.                 trucksCounter++;
  43.                 averageTruckHP += horsePower;
  44.  
  45.                 Vehicle vehicle = new Vehicle("Truck", model, color, horsePower);
  46.                 vehicles.Add(vehicle);
  47.             }
  48.         }
  49.  
  50.         while (true)
  51.         {
  52.             string model = Console.ReadLine();
  53.  
  54.             if (model == "Close the Catalogue")
  55.             {
  56.                 break;
  57.             }
  58.  
  59.             foreach (var vehicle in vehicles)
  60.             {
  61.                 if (model == vehicle.Model)
  62.                 {
  63.                     Console.WriteLine("Type: {0}", vehicle.Type);
  64.                     Console.WriteLine("Model: {0}", vehicle.Model);
  65.                     Console.WriteLine("Color: {0}", vehicle.Color);
  66.                     Console.WriteLine("Horsepower: {0}", vehicle.HorsePower);
  67.                 }
  68.             }
  69.         }
  70.         double averageCars = 0;
  71.         double averageTrucks = 0;
  72.  
  73.         if (carsCounter >= 1)
  74.         {
  75.             averageCars = averageCarsHP / carsCounter;
  76.         }
  77.  
  78.         if (trucksCounter >= 1)
  79.         {
  80.             averageTrucks = averageTruckHP / trucksCounter;
  81.  
  82.         }
  83.  
  84.         Console.WriteLine("Cars have average horsepower of: {0:f2}.", averageCars);
  85.         Console.WriteLine("Trucks have average horsepower of: {0:f2}.", averageTrucks);
  86.     }
  87. }
  88.  
  89. class Vehicle
  90. {
  91.     public string Type { get; set; }
  92.     public string Model { get; set; }
  93.     public string Color { get; set; }
  94.     public double HorsePower { get; set; }
  95.  
  96.     public Vehicle(string type, string model, string color, double horsePower)
  97.     {
  98.         this.Type = type;
  99.         this.Model = model;
  100.         this.Color = color;
  101.         this.HorsePower = horsePower;
  102.     }
  103. } // .
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top