Defining Classes - Exercise | 10. SoftUni Parking
Здравейте!
Днес доста време я мъча тази задача и стигнах до 92/100 точки. Само 8-мият тест ми гърми... Моля за малко съдействие.
Моето решение:
Благодаря!
Здравейте!
Днес доста време я мъча тази задача и стигнах до 92/100 точки. Само 8-мият тест ми гърми... Моля за малко съдействие.
Моето решение:
Благодаря!
public int Count
{
get { return cars.Count; }
set { this.Count = cars.Count; }
}
Setter isn't right here, should either set with private field count or left without setter.
92% usually indicates minor problem, either indicating a missing field or incomplete output string.
Try the following:
public int Count
{
get { return cars.Count; }
}
Demo Code:
using System;
using System.Collections.Generic;
namespace SoftUniParking
{
public class Parking
{
private Dictionary<string, Car> carList = new Dictionary<string, Car>();
private int capacity;
private int count;
public Parking(int capacity)
{
this.Capacity = capacity;
}
public Dictionary<string, Car> CarList
{
get
{
return this.carList;
}
set
{
this.carList = value;
}
}
public int Capacity
{
get
{
return this.capacity;
}
set
{
this.capacity = value;
}
}
public int Count
{
get
{
return this.count;
}
private set
{
this.count = value;
}
}
public string AddCar(Car car)
{
if (this.CarList.ContainsKey(car.RegistrationNumber))
{
return "Car with that registration number, already exists!";
}
else if(this.Capacity == 0)
{
return $"Parking is full!";
}
else
{
this.Capacity--;
this.Count++;
this.CarList.Add(car.RegistrationNumber, car);
return $"Successfully added new car {car.Make} {car.RegistrationNumber}";
}
}
public string RemoveCar(string registration)
{
if (this.CarList.ContainsKey(registration))
{
this.CarList.Remove(registration);
this.Count--;
this.Capacity++;
return $"Successfully removed {registration}";
}
else
{
return $"Car with that registration number, doesn't exist!";
}
}
public Car GetCar(string registration)
{
return this.CarList[registration];
}
public void RemoveSetOfRegistrationNumber(List<string> RegistrationNumbers)
{
foreach (var number in RegistrationNumbers)
{
if (this.CarList.ContainsKey(number))
{
this.CarList.Remove(number);
this.Count--;
this.Capacity++;
}
}
}
}
}
Здравей!
Благодаря за насоката! Успях да я реша.
Поздрави!