Computers and Technology

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?

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 10:30, badpotterchris
How would you categorize the software that runs on mobile devices? break down these apps into at least three basic categories and give an example of each.
Answers: 1
image
Computers and Technology, 23.06.2019 15:20, manarhizam12
An ou structure in your domain has one ou per department, and all the computer and user accounts are in their respective ous. you have configured several gpos defining computer and user policies and linked the gpos to the domain. a group of managers in the marketing department need different policies that differ from those of the rest of the marketing department users and computers, but you don't want to change the top-level ou structure. which of the following gpo processing features are you most likely to use? a, block inheritance b, gpo enforcement c, wmi filtering d, loopback processing
Answers: 3
image
Computers and Technology, 23.06.2019 16:00, CalCDanG
What is the biggest difference between section breaks and regular page breaks? section breaks are more difficult to add than page breaks. section breaks make it easier for you to view the document as an outline. section breaks allow you to have areas of the document with different formatting. section breaks are smaller than regular page breaks.
Answers: 2
image
Computers and Technology, 23.06.2019 21:30, maddietomlinson113
Examine the list below. which factors positively affect lifetime income? check all that apply.
Answers: 1
Do you know the correct answer?
Create an application in C# named CarDemo that declares at least two Car objects and demonstrates ho...

Questions in other subjects: