subject

Create an application in C# named CarDemo that declares at least two Car objects and demonstrates how they can be incremented using an overloaded ++ operator. Create a Car class that contains the following properties:

Model - The car model (as a string)

Mpg The car's miles per gallon (as a double)

Include two overloaded constructors. One accepts parameters for the model and miles per gallon; the other accepts a model and sets the miles per gallon to 20.

Overload the ++ operator that increases the miles per gallon value by 1. The CarDemo application creates at least one Car using each constructor and displays the Car values both before and after incrementation.

this is what i have:

using static System. Console;

class CarDemo

{

static void Main()

{

Car c1 = new Car("Camero", 25);

Car c2 = new Car("Mustang");

Display("Camero at beginning", c1);

++c1;

Display("Camero after prefix increment", c1);

Display("Mustang at beginning", c2);

++c2;

Display("Mustang after prefix increment", c2);

}

public static void Display(string message, Car)

{

WriteLine(Mpg);

}

class Car

{

private string Model

{

get

{

return model;

}

set

{

model = value;

}

}

private double Mpg

{

get

{

return mpg;

}

set

{

mpg = value;

}

}

public Car(string model, double mpg)

{

Model = model;

Mpg = mpg;

}

public Car(string model)

{

Model = model;

Mpg = 20;

}

public static Car operator++(Car c)

{

++c. Mpg;

return c;

}

}

}

what am i doing wrong?

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:30
Why would a programmer use the logical operator and in an if statement? a: when an action is to be taken that requires both conditions to be falseb: when an action is to be taken that requires both conditions to be truec: when an action is to be taken that requires the first condition to be falsed: when an action is to be taken that requires the second condition to be truei took the test and the answer is b.
Answers: 3
question
Computers and Technology, 22.06.2019 17:00
Your company has 1,500 desktop computers running windows 7. you want to upgrade them to windows 10. which type of microsoft license would be best suited in this situation?
Answers: 3
question
Computers and Technology, 22.06.2019 20:00
What side length would you specify if you were required to create a regular hexagonal plate that was composed of 33 cm(squared) of sheet metal? dimension the side length to 0.1 cm
Answers: 2
question
Computers and Technology, 23.06.2019 07:30
What part of the interface displays the external references contained in a selected cell? the status bar the review tab the scroll bar the formula bar
Answers: 1
You know the right answer?
Create an application in C# named CarDemo that declares at least two Car objects and demonstrates ho...
Questions
question
Mathematics, 30.08.2019 01:00
question
Mathematics, 30.08.2019 01:00
question
Mathematics, 30.08.2019 01:00
Questions on the website: 13722360