using System;
namespace LearnInterfaces
{
class Truck : IAutomobile
{
public string LicensePlate
{ get; }
public double Speed
{ get; private set; }
public int Wheels
{ get; }
public double Weight
{ get; }
public void Honk()
{
Console.WriteLine("HONK!");
}
public Truck (double speed, double weight)
{
Speed = speed;
Weight = weight;
LicensePlate = Tools.GenerateLicensePlate();
if (Weight < 400)
{ Wheels = 8;}
else
{ Wheels = 12; }
public void SpeedUp(double speed)
{
Speed = Speed + speed;
}
}
}
}
The error in question pertains to public void SpeedUp(double speed). This method worked correctly in previous exercises, and seems to written the same in the code solution, but I still cannot deduce what exactly I’m doing wrong here. Could anyone help?
When you call the SpeedUp method, are you providing an argument? My guess would be no, since the method is intended to double the current speed. Your method takes a speed parameter, and adds it to the current value of Speed. That wouldn’t necessarily result in doubling the Truck object’s Speed value. For example, myTruck.SpeedUp(-25) would reduce the speed.
Forgive my silliness in assuming you intended to double the speed. Tired I guess. I’ve looked at the exercise, and see what we’re tying to do now. The error you have is due to your SpeedUp method expecting an argument since you’ve included a parameter.
When the SCT for the lesson is testing your code, it calls the method, but does not include an argument. Calling the SpeedUp method should increment the Speed property value by 5 which your code will do, but you need to delete the parameter from the method declaration. The method should not accept any parameters.
Edit:
While the above is true (generates: error CS7036: There is no argument given that corresponds to the required formal parameter 'Speed' of 'Truck.SpeedUp(double)' [/home/ccuser/workspace/csharp-interfaces-finish-truck-class/LearnInterfaces.csproj]), it isn’t the source of the error you reported. I just ran your code, and now see the issue. You’ve included the SpeedUp method inside your constructor method. It needs to be inside the Truck class, but not inside the constructor. Cleaning up your indentation (making it consistent) will help avoid these errors in the future.