Професионална програма
Loading...
+ Нов въпрос
DoroteyaDoncheva avatar DoroteyaDoncheva 11 Точки

Defining Classes - Exercise | 10. SoftUni Parking

Здравейте!
Днес доста време я мъча тази задача и стигнах до 92/100 точки. Само 8-мият тест ми гърми... Моля за малко съдействие.

Условие: https://softuni.bg/downloads/svn/csharp-fundamentals/2021-Jan/CSharp-Advanced/06. CSharp-Advanced-Defining-Classes/06. CSharp-Advanced-Defining-Classes-Exercises.docx

Моето решение:

Car Class - Pastebin.com

Parking class - Pastebin.com

StartUp class - Pastebin.com

Благодаря!

0
Module: C# Advanced 30/10/2021 20:48:34
Axiomatik avatar Axiomatik 1624 Точки
        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++;
                }
            }
        }
    }
}

 

 

 

0
DoroteyaDoncheva avatar DoroteyaDoncheva 11 Точки

Здравей!

Благодаря за насоката! Успях да я реша. enlightened

Поздрави!

2