Use c # to complete the following code,Creating a Car class A class is a self-contained piece of software that is able to function on it own. We will model a car in software. Car Class Properties Year : int «private set» Manufacturer : string «private set» Model : string «private set» IsDrivable : bool «private set» Price : double «private set» Methods«constructor» Car(year : int, manufacturer : string, model : string, price : double, isDrivable: bool = true) PrintInfo() : void Description of field members: 1. year: this private member represents the year value of this object 2. manufacturer: this private member represents the manufacturer of this car 3. model: this private member represents the model of this car 4. isDrivable: this private member indicates if this car be driven 5. price: this private member represents the selling price of this car Constructor: 1. public Car(int year, string manufacturer, string model, double price, bool isDrivable = true): this is the constructor of this class. It takes five arguments and assigns them to the appropriate fields. You will assume that all the arguments will be sane (i.e. the values will not break your program). Apology: UML and some newer languages specify the type after the identifier. C# on the other hand requires that you specify the type and then the identifier
时间: 2024-03-25 10:41:16 浏览: 63
RH850U2A DATASHEET 英文
Sure, here is the completed code:
```
public class Car
{
public int Year { get; private set; }
public string Manufacturer { get; private set; }
public string Model { get; private set; }
public bool IsDrivable { get; private set; }
public double Price { get; private set; }
public Car(int year, string manufacturer, string model, double price, bool isDrivable = true)
{
Year = year;
Manufacturer = manufacturer;
Model = model;
Price = price;
IsDrivable = isDrivable;
}
public void PrintInfo()
{
Console.WriteLine($"Year: {Year}, Manufacturer: {Manufacturer}, Model: {Model}, IsDrivable: {IsDrivable}, Price: {Price}");
}
}
```
This code defines a Car class with the specified properties and methods. The constructor takes in the necessary arguments to initialize the object, and the PrintInfo method prints out the information about the car object.
阅读全文