Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//Creates a Car class // You can construct a Car using a price and color // or j

ID: 3545977 • Letter: #

Question

//Creates a Car class

// You can construct a Car using a price and color

// or just a price, in which case a Car is black

// or no parameters, in which case a Car is $10,000 and black

using System;

class FixedDebugNine3

{

    public static void Main()

    {

        Car myCar = new Car(32000, "red");

        Car yourCar = new Car(14000);

        Car theirCar = new Car();

        Console.WriteLine("My {0} car cost {1}", myCar.Color,

           myCar.Price.ToString("c2"));

        Console.WriteLine("Your {0} car cost {1}",

           yourCar.Color, yourCar.Price.ToString("c2"));

        Console.WriteLine("Their {0} car cost {1}",

           theirCar.Color, theirCar.Price.ToString("c2"));

    }

}

class Car

{

    private string color;

    private int price;

    public Car()

    {

        color = "black";

        Price = 10000;


    }

    public Car(int price)

    {


    }

    public Car(int price, string color)

    {

        Price = price;

        Color = color;

    }

    public string Color

    {

        get

        {

            return color;

        }

        set

        {

            color = value;

        }

    }

    public int Price

    {

        get

        {

            return Price;

        }

        set

        {

            price = value;

        }

    }

}

Explanation / Answer

Sample Output



My red car cost ?32,000.00

Your car cost ?14,000.00

Their black car cost ?10,000.00




Code



//Creates a Car class

// You can construct a Car using a price and color

// or just a price, in which case a Car is black

// or no parameters, in which case a Car is $10,000 and black

using System;

class FixedDebugNine3

{

public static void Main()

{

Car myCar = new Car(32000, "red");

Car yourCar = new Car(14000);

Car theirCar = new Car();

Console.WriteLine("My {0} car cost {1}", myCar.Color,

myCar.Price.ToString("c2"));

Console.WriteLine("Your {0} car cost {1}",

yourCar.Color, yourCar.Price.ToString("c2"));

Console.WriteLine("Their {0} car cost {1}",

theirCar.Color, theirCar.Price.ToString("c2"));

}

}

















class Car

{

private string color;

private int price;

public Car()

{

color = "black";

Price = 10000;


}

public Car(int price)

{

Price = price;

}

public Car(int price, string color)

{

Price = price;

Color = color;

}

public string Color

{

get

{

return color;

}

set

{

color = value;

}

}

public int Price

{

get

{

return price;

}

set

{

price = value;

}

}

}