Я супер тупик. Я пытаюсь создать программу, которая позволяет пользователю создать «автомобиль» и объявить марку, модель и цвет этого автомобиля.
Код не закончен (и размещен ниже). Я получаю несколько ошибок на каждом из методов получения и установки в классе Automobile.
Например, я получаю сообщение об ошибке «Не удается неявно преобразовать тип« double »в« строку »». в строке кода, которая гласит return make
и в строке make = paramMake
, а также в остальных методах получения и установки.
Есть идеи?
namespace Program_4cs
{
class Automobile
{
//2.
//a). PDDC
public Automobile()
{
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("a). Automobile PDDC set.");
}
//PDC
public Automobile(string paramMake, string paramModel, string paramColor)
{
string make = paramMake;
string model = paramModel;
string color = paramColor;
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("a). Automobile PDC set.");
}
//b). Getters and Setters
public string GetMake()
{
return make;
}
public void SetMake(string paramMake)
{
make = paramMake;
}
public string GetModel()
{
return model;
}
public void SetModel(string paramModel)
{
model = paramModel;
}
public string GetColor()
{
return color;
}
public void SetColor(string paramColor)
{
color = paramColor;
}
//c). Speed changing members
public double GetSpeed()
{
return speed;
}
public void SetSpeed(double paramSpeed)
{
speed = paramSpeed;
}
public void IncreaseSpeed(double paramIncreaseSpeedBy)
{
speed = speed + paramIncreaseSpeedBy;
}
public void DecreaseSpeed(double paramDecreaseSpeedBy)
{
speed = speed - paramDecreaseSpeedBy;
}
public void ShowSpeed(double paramShowSpeed)
{
speed = paramShowSpeed;
}
//d). instance members
private double speed;
private double make;
private double model;
private double color;
}
class Program
{
static void Main(string[] args)
{
//1.
//Ouput a header in the console
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("1. This is Program-4.");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Press any key to continue.");
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("How many automobiles would you like to create?");
Console.ForegroundColor = ConsoleColor.White;
int numOfAutomobiles = int.Parse(Console.ReadLine());
Automobile[] listOfAutomobiles = new Automobile[numOfAutomobiles];
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Please input model, and color");
Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < listOfAutomobiles.Length; i++)
{
Console.WriteLine("Please enter the make: ");
String make = Console.ReadLine();
Console.WriteLine("Please enter the model: ");
String model = Console.ReadLine();
Console.WriteLine("Please enter the color: ");
string color = Console.ReadLine();
Automobile newCar = new Automobile(make, model, color);
listOfAutomobiles[i] = newCar;
}
Console.ReadKey();
}
}
}
Заранее спасибо!