Help с проблем номер 6. Vehicle Catalogue от Objects and Classes
Здравейте колеги,
Видях че веще има въпрос към проблема от друг колега, но неговото питане е относно Compile Time Error. Надявам се че не е проблем че питам още нещо.
Отговорите от example ми излизат, но когато пусна решението в Judge, от 6 проверки, първите 4 гърмат, последните 2 излизат.
Някой може ли да ми каже къде бъркам.
Ето го кода:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _0.Practice
{
class Program
{
static void Main()
{
GetVehicleInfoFromUser();
PrintVehiclesByModel();
Vehicle.PrintAverageHorsePower();
}
static void GetVehicleInfoFromUser()
{
bool isWorking = true;
while (isWorking == true)
{
string input = Console.ReadLine();
char[] separators = new char[] { ' ' };
string[] inputArray = input.Split(separators, StringSplitOptions.RemoveEmptyEntries);
if (inputArray[0] == "car")
{
Vehicle.listOfAllVehicles.Add(new Vehicle("Car", inputArray[1], inputArray[2], double.Parse(inputArray[3])));
}
else if (inputArray[0] == "truck")
{
Vehicle.listOfAllVehicles.Add(new Vehicle("Truck", inputArray[1], inputArray[2], double.Parse(inputArray[3])));
}
else if (inputArray[0] == "End")
{
isWorking = false;
}
}
}
static void PrintVehiclesByModel()
{
bool isWorking = true;
while (isWorking == true)
{
string model = Console.ReadLine();
if (model == "Close the Catalogue")
{
isWorking = false;
}
else
{
Vehicle.PrintVehicleInfo(model);
}
}
}
}
class Vehicle
{
// fields
string vehicleType = null;
string vehicleModel = null;
string vehicleColor = null;
double vehicleHorsepower = 0;
public static List<Vehicle> listOfAllVehicles = new List<Vehicle>();
// constructor
public Vehicle(string vehicleType, string vehicleModel, string vehicleColor, double vehicleHorsepower)
{
this.vehicleType = vehicleType;
this.vehicleModel = vehicleModel;
this.vehicleColor = vehicleColor;
this.vehicleHorsepower = vehicleHorsepower;
}
// methods
public static void PrintVehicleInfo(string model)
{
for (int i = 0; i < listOfAllVehicles.Count; i++)
{
if (listOfAllVehicles[i].vehicleModel == model)
{
Console.WriteLine("Type: {0}", listOfAllVehicles[i].vehicleType);
Console.WriteLine("Model: {0}", listOfAllVehicles[i].vehicleModel);
Console.WriteLine("Color: {0}", listOfAllVehicles[i].vehicleColor);
Console.WriteLine("Horsepower: {0}", listOfAllVehicles[i].vehicleHorsepower);
break;
}
}
}
public static void PrintAverageHorsePower()
{
double sumCars = 0;
double countCars = 0;
double sumTrucks = 0;
double countTrucks = 0;
for (int i = 0; i < listOfAllVehicles.Count; i++)
{
if (listOfAllVehicles[i].vehicleType == "Car")
{
sumCars += listOfAllVehicles[i].vehicleHorsepower;
countCars++;
}
else if (listOfAllVehicles[i].vehicleType == "Truck")
{
sumTrucks += listOfAllVehicles[i].vehicleHorsepower;
countTrucks++;
}
}
Console.WriteLine("Cars have average horsepower of: {0:F2}.", sumCars / countCars);
Console.WriteLine("Trucks have average horsepower of: {0:F2}.", sumTrucks / countTrucks);
}
}
}