Софтуерно Инженерство
Loading...
+ Нов въпрос
Nvmzax avatar Nvmzax 0 Точки

Compile time error при 08. Vehicle Catalogue от Objects and Classes - Lab

Здравейте!

Бих бил благодарен ако някой ми обясни къде бъркам и защо цялото нещо гърми при проверка в Judge толкова грандиозно, при положние, че на моята машна си се компилира нормално. Не съм използвал нищо странно: System, System.Collections.Generic, System.Linq, System.Text

Error:

Compiled file is missing. Compiler output: ...\tmpCECA.tmp(69,31): error CS1503: Argument 1: cannot convert from 'string' to 'char*'
...\tmpCECA.tmp(57,31): error CS1503: Argument 1: cannot convert from 'string' to 'char*'

 

Също така, ако на някой не му харесва нещо друго, не свързано с текущия ми въпрос, моля пишете.

Ето го и кода

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vehicle_Catalog
{
    class Program
    {
        static List<string> Fragmented = new List<string>();

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            Fragmented = input.Split('/').ToList();
            string command = Fragmented[0];
            Catalog collection = new Catalog();
            while (command != "end")
            {
                if (command == "Car")
                {
                    Car newCar = new Car
                    {
                        Brand = Fragmented[1],
                        Model = Fragmented[2],
                        HorsePower = double.Parse(Fragmented[3])
                    };
                    collection.CarsCatalog.Add(newCar);
                }
                else
                {
                    Truck newTruck = new Truck
                    {
                        Brand = Fragmented[1],
                        Model = Fragmented[2],
                        Weight = double.Parse(Fragmented[3])
                    };
                    collection.TrucksCatalog.Add(newTruck);
                }

                Fragmented = Console.ReadLine().Split('/').ToList();
                command = Fragmented[0];
            }

            Console.Write(collection.ToString());
        }
    }

    public class Truck
    {
        public string Brand { get; set; }
        public string Model { get; set; }
        public double Weight { get; set; }

        public override string ToString()
        {
            return new string($"{Brand}: {Model} - {Weight}kg");
        }
    }

    public class Car
    {
        public string Brand { get; set; }
        public string Model { get; set; }
        public double HorsePower { get; set; }

        public override string ToString()
        {
            return new string($"{Brand}: {Model} - {HorsePower}hp");
        }
    }

    public class Catalog
    {
        public List<Truck> TrucksCatalog { get; set; }
        public List<Car> CarsCatalog { get; set; }

        public Catalog()
        {
            TrucksCatalog = new List<Truck>();
            CarsCatalog = new List<Car>();
        }

        public override string ToString()
        {
            List<Car> orderedCars = CarsCatalog.OrderBy(c => c.Brand).ToList();
            List<Truck> orderedTrucks = TrucksCatalog.OrderBy(t => t.Brand).ToList();
            StringBuilder sb = new StringBuilder();
            if (orderedCars.Count > 0)
            {
                sb.AppendLine("Cars:");
                foreach (Car car in orderedCars)
                {
                    sb.AppendLine(car.ToString());
                }
            }
            if (orderedTrucks.Count > 0)
            {
                sb.AppendLine("Trucks:");
                foreach (Truck truck in orderedTrucks)
                {
                    sb.AppendLine(truck.ToString());
                }
            }

            return sb.ToString();
        }
    }
}

 

Тагове:
0
Programming Fundamentals 26/02/2019 23:45:02
Nvmzax:
Question already answered.
plus1pxl avatar plus1pxl 16 Точки
Best Answer

Пробвай да смениш:

        public override string ToString()
        {
            return new string($"{Brand}: {Model} - {Weight}kg");
        }

на:

        public override string ToString()
        {
            return $"{Brand}: {Model} - {Weight}kg";
        }

и респективно за class Car

0
Nvmzax avatar Nvmzax 0 Точки

Благодаря! Ще проверя дали това ще реши проблема малко по-късно. 

Мога ли да помоля за обяснение,  защо връщането на нов string при изпълнението на метод не може да се компилира от Judge а на машината в къщи работи? 

0
06/03/2019 22:30:27
souls00 avatar souls00 0 Точки

да, точно това имах предвид. happy wheels

0
ethancarter avatar ethancarter 1 Точки

This instructional exercise shows you how to announce classes, portray traits by means of fields, depict practices by means of techniques, introduce objects through constructors, and start up objects from classes and access their individuals. By : Best Assignment Writing Services

0
1
williamdavid avatar williamdavid 0 Точки

A team comprising of experienced and Professional Essay Writer, researchers, editors, proofreaders and customer support executives make Essays Tigers the only service that students will ever need for all their academic assignments. The icing on the top is that our prices are low as well.

0
alfiedeyes avatar alfiedeyes 1 Точки

Buy custom assignments prepared by professional writers of our agency. Our online assignment writing services are confidential, reliable and helpful.

Our essay writing service is the best place to order high quality academic papers online. We cover almost any subject and discipline. We're available 24/7.

You need custom dissertation writing service help cause the project is too hard. Choose dissertation author here yourself to get one-to-one writing help.

Our professional thesis writing service UK will do all the work for you! Our experts can provide you with an excellent paper at a low price 24/7!

0
1