Loading...
Elena123456 avatar Elena123456 235 Точки

Parking 92/100 - C# Advanced Exam - 28 June 2020

Здравейте,

моля за помощ- пети тест гърми и не успявам да разбера къде е проблема.

клас Car - https://pastebin.com/ff155QRC

клас Parking - https://pastebin.com/Pm7LF0mu

Judge- https://judge.softuni.bg/Contests/Practice/Index/2444#2

 

Условие:

Preparation

Download the skeleton provided in Judge. Do not change the StartUp class or its namespace.

Problem description

Your task is to create a repository, which stores items by creating the classes described below.

First, write a C# class Car with the following properties:

  • Manufacturer: string
  • Model: string
  • Year: int

The class constructor should receive manufacturer, model and year and override the ToString() method in the following format:

"{manufacturer} {model} ({year})"

Next, write a C# class Parking that has data (a collection, which stores the entity Car). All entities inside the repository have the same properties. Also, the Parking class should have those properties:

  • Type: string
  • Capacity: int

The class constructor should receive type and capacity, also it should initialize the data with a new instance of the collection. Implement the following features:

  • Field datacollection that holds added cars
  • Method Add(Car car) – adds an entity to the data if there is an empty cell for the car.
  • Method Remove(string manufacturer, string model) – removes the car by given manufacturer and model, if such exists, and returns bool.
  • Method GetLatestCar() – returns the latest car (by year) or null if have no cars.
  • Method GetCar(string manufacturer, string model) – returns the car with the given manufacturer and model or null if there is no such car.
  • Getter Count – returns the number of cars.
  • returns a string in the following format:
    • "The cars are parked in {parking type}:
      {Car1}
      {Car2}
      (…)
      "

Constraints

  • The combinations of manufacturers and models will be always unique.
  • The year of the cars will always be positive.
  • There won't be cars with the same years.

Examples

This is an example how the Parking class is intended to be used.

Sample code usage

// Initialize the repository

Parking parking = new Parking("Underground parking garage", 5);

 

// Initialize entity

Car volvo = new Car("Volvo", "XC70", 2010);

 

// Print Car

Console.WriteLine(volvo); // Volvo XC70 (2010)

 

// Add Car

parking.Add(volvo);

 

// Remove Car

Console.WriteLine(parking.Remove("Volvo", "XC90")); // False

Console.WriteLine(parking.Remove("Volvo", "XC70")); // True

 

Car peugeot = new Car("Peugeot", "307", 2011);

Car audi = new Car("Audi", "S4", 2005);

 

parking.Add(peugeot);

parking.Add(audi);

 

// Get Latest Car

Car latestCar = parking.GetLatestCar();

Console.WriteLine(latestCar); // Peugeot 307 (2011)

 

// Get Car

Car audiS4 = parking.GetCar("Audi", "S4");

Console.WriteLine(audiS4); // Audi S4 (2005)

 

// Count

Console.WriteLine(parking.Count); // 2

 

// Get Statistics

Console.WriteLine(parking.GetStatistics());

// The cars are parked in Underground parking garage:

// Peugeot 307(2011)

// Audi S4(2005)

Submission

Zip all the files in the project folder except bin and obj folders.

 

Тагове:
0
C# Advanced
Axiomatik avatar Axiomatik 2422 Точки
Best Answer

Hi,

Usually, when judge only gives 91% or 92%, this means that something is wrong with the final output method that overwrites ToString() and summarizes all data in the given class. Try to change:

        public string GetStatistics()
        {
            var sb = new StringBuilder();
            string information = $"The cars are parked in {this.Type} parking garage.";
            sb.AppendLine(information);
 
            foreach (var car in this.data)
            {
                sb.AppendLine(car.ToString());
            }
 
            return sb.ToString().TrimEnd();
        }

to

        public string GetStatistics()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine($"The cars are parked in {this.Type}:");
            foreach (var car in this.data)
            {
                sb.AppendLine(car.ToString());
            }

            return sb.ToString().TrimEnd();
        }

:-)

1
Elena123456 avatar Elena123456 235 Точки

Hi @ Axiomatik ,

thanks a lot for your comment and for every other. If you didn't help me, I couldn't do anything in programming exercises, especially in OOP.

Thanks a lot and to @MartinBG , who helped me in the basic module, show me how to work with multidimensional arrays and streams. 

Thanks and to @ nickwork , who helped me a lot in basic and fundamental.

I couldn't forget anyone of you and your helping ,and I will be forever gratefull!

Take care and I wish you all the best!

By the way this is my github https://github.com/elipopovadev and if any of you have github I would follow you.

 

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.