Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace TeamworkProjects
- {
- class Car
- {
- public string Type { get; set; }
- public string Model { get; set; }
- public string Color { get; set; }
- public int Power { get; set; }
- public Car (string type, string model, string color, int power)
- {
- this.Type = type;
- this.Model = model;
- this.Color = color;
- this.Power = power;
- }
- public override string ToString()
- {
- return $"Type: {this.Type}\nModel: {this.Model}\nColor: {this.Color}\nHorsepower: {this.Power}\n";
- }
- }
- class Truck
- {
- public string Type { get; set; }
- public string Model { get; set; }
- public string Color { get; set; }
- public int Power { get; set; }
- public Truck (string type, string model, string color, int power)
- {
- this.Type = type;
- this.Model = model;
- this.Color = color;
- this.Power = power;
- }
- public override string ToString()
- {
- return $"Type: {this.Type}\nModel: {this.Model}\nColor: {this.Color}\nHorsepower: {this.Power}\n";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- string input;
- List<Car> cars = new List<Car>();
- List<Truck> trucks = new List<Truck>();
- double carPower = 0;
- double carAdd = 0;
- double truckPower = 0;
- double truckAdd = 0;
- while ((input = Console.ReadLine()) != "End")
- {
- string[] array = input.Split();
- string type = array[0];
- string model = array[1];
- string color = array[2];
- int power = int.Parse(array[3]);
- //Console.WriteLine(type);
- if (type == "car")
- {
- type = "Car";
- Car carList = new Car(type, model, color, power);
- cars.Add(carList);
- carPower += power;
- carAdd++;
- }
- else
- {
- type = "Truck";
- Truck truckList = new Truck(type, model, color, power);
- trucks.Add(truckList);
- truckPower += power;
- truckAdd++;
- //Console.WriteLine(truckAdd);
- }
- }
- string output;
- while((output = Console.ReadLine()) != "Close the Catalogue")
- {
- Console.Write(cars.Find(x => x.Model == output));
- Console.Write(trucks.Find(x => x.Model == output));
- }
- //Console.WriteLine();
- double carAv = 0;
- if (carAdd != 0)
- {
- carAv = carPower / carAdd;
- }
- double truckAv = 0;
- if (truckAdd != 0)
- {
- truckAv = truckPower / truckAdd;
- }
- Console.WriteLine($"Cars have average horsepower of: {carAv:f2}.");
- Console.WriteLine($"Trucks have average horsepower of: {truckAv:f2}.");
- //Console.WriteLine($"Trucks have average horsepower of: {truckAv:f2}.");
- //Console.WriteLine($"Cars have average horsepower of: {carAv:f2}.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement