06. Vehicle Catalogue от Objects and Classes - Exercise
Здравейте приятели имам проблем с тази задата дава ми 33/100
Ето до къде съм стигнал: https://pastebin.com/uCk0bH6Y
Ето и задачата:
Vehicle Catalogue
You have to make a catalogue for vehicles. You will receive two types of vehicle – car or truck.
Until you receive the command “End” you will receive lines of input in the format:
{typeOfVehicle} {model} {color} {horsepower}
After the “End” command, you will start receiving models of vehicles. Print for every received vehicle its data in the format:
Type: {typeOfVehicle}
Model: {modelOfVehicle}
Color: {colorOfVehicle}
Horsepower: {horsepowerOfVehicle}
When you receive the command “Close the Catalogue”, stop receiving input and print the average horsepower for the cars and for the trucks in the format:
{typeOfVehicles} have average horsepower of {averageHorsepower}.
The average horsepower is calculated by dividing the sum of horsepower for all vehicles of the type by the total count of vehicles from the same type.
Format the answer to the 2nd decimal point.
Constraints
The type of vehicle will always be car or truck.
You will not receive the same model twice.
The received horsepower will be integer in the interval [1…1000]
You will receive at most 50 vehicles.
Single whitespace will be used for separator.
Ето за тест:
https://judge.softuni.bg/Contests/Practice/Index/1215#5
Благодаря много!
Може ли малко по ясна обяснение на тази част?
double sumCar = car.Count > 0 ? car.Average(x => x.Horsepower) : 0.0;
Тернарен оператор (Ternary operator). Общо взето кратък запис нa if/else конструкция, удобна е за такива случаи като този.
Ако има поне едно превозно средство в листа ще се изпълни .Average() extension метода върху колекцията и ще запише получения резултат, но ако е празна ще запише 0.0.