chore: document Car and remove getter setter
This commit is contained in:
@@ -6,63 +6,109 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace CarManagerV3
|
namespace CarManagerV3
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class <c>Car</c> represents a car with various attributes such as make, model, year, color, mileage, and price.
|
||||||
|
/// </summary>
|
||||||
public class Car
|
public class Car
|
||||||
{
|
{
|
||||||
int id;
|
public int Id;
|
||||||
string make;
|
public string Make;
|
||||||
string model;
|
public string Model;
|
||||||
int year;
|
public int Year;
|
||||||
string color;
|
public string Color;
|
||||||
int mileage;
|
public int Mileage;
|
||||||
decimal price;
|
public decimal Price;
|
||||||
int order;
|
public int Order;
|
||||||
|
|
||||||
|
//TODO: Make Id read-only CUID. Allows for better integrity, especially when merging.
|
||||||
|
//TODO: Add buying price and automatic calculation of profit/loss with selling price suggestion.
|
||||||
|
//TODO: Add Buying Date.
|
||||||
|
//TODO: Add sold boolean and Sold Date.
|
||||||
|
//TODO: Add "hidden" attribute for cars that are not for sale anymore but should be kept in the database for records.
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Car"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The unique identifier as an Integer.</param>
|
||||||
|
/// <param name="make">The make / manufacturer of the car.</param>
|
||||||
|
/// <param name="model">The model.</param>
|
||||||
|
/// <param name="year">The year the car was built.</param>
|
||||||
|
/// <param name="color">The color of the car.</param>
|
||||||
|
/// <param name="mileage">The current mileage on the car.</param>
|
||||||
|
/// <param name="price">The selling-price of the car.</param>
|
||||||
|
/// <param name="order">The order.</param>
|
||||||
public Car(int id, string make, string model, int year, string color, int mileage, decimal price, int order = 0)
|
public Car(int id, string make, string model, int year, string color, int mileage, decimal price, int order = 0)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.Id = id;
|
||||||
this.make = make;
|
this.Make = make;
|
||||||
this.model = model;
|
this.Model = model;
|
||||||
this.year = year;
|
this.Year = year;
|
||||||
this.color = color;
|
this.Color = color;
|
||||||
this.mileage = mileage;
|
this.Mileage = mileage;
|
||||||
this.price = price;
|
this.Price = price;
|
||||||
this.order = order;
|
this.Order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Id { get { return id; } set { id = value; } }
|
|
||||||
public string Make { get { return make; } set { make = value; } }
|
|
||||||
public string Model { get { return model; } set { model = value; } }
|
|
||||||
public int Year { get { return year; } set { year = value; } }
|
|
||||||
public string Color { get { return color; } set { color = value; } }
|
|
||||||
public int Mileage { get { return mileage; } set { mileage = value; } }
|
|
||||||
public decimal Price { get { return price; } set { price = value; } }
|
|
||||||
public int Order { get { return order; } set { order = value; } }
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts to string in a custom readable format.
|
||||||
|
/// <example>
|
||||||
|
/// For Example:
|
||||||
|
/// Skoda Fabia (2015)
|
||||||
|
/// </example>
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// A <see cref="System.String" /> that represents this instance.
|
||||||
|
/// </returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{make} {model} ({year})";
|
return $"{this.Make} {this.Model} ({this.Year})";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts to default CSV savable string.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public string ToCsvString()
|
public string ToCsvString()
|
||||||
{
|
{
|
||||||
return $"{id};{make};{model};{year};{color};{mileage};{price}";
|
return $"{this.Id};{this.Make};{this.Model};{this.Year};{this.Color};{this.Mileage};{this.Price}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Add error handling for malformed CSV strings and detection for missing fields.
|
||||||
|
//TODO: Add support for different CSV formats (e.g., different delimiters, quoted fields, etc.).
|
||||||
|
//TODO: Add support for nil or optional fields.
|
||||||
|
//TODO: Add detectin for invalid data / nonsensical values (e.g., negative mileage or year in the future). / Validate it actually is a car.
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="Car"/> instance from a CSV string in the default format.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="csv">The CSV Line.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A new <see cref="Car"/> instance.
|
||||||
|
/// </returns>
|
||||||
public static Car FromCsvString(string csv)
|
public static Car FromCsvString(string csv)
|
||||||
{
|
{
|
||||||
string[] parts = csv.Split(';');
|
string[] parts = csv.Split(';');
|
||||||
return new Car(int.Parse(parts[0]), parts[1], parts[2], int.Parse(parts[3]), parts[4], int.Parse(parts[5]), decimal.Parse(parts[6]));
|
return new Car(int.Parse(parts[0]), parts[1], parts[2], int.Parse(parts[3]), parts[4], int.Parse(parts[5]), decimal.Parse(parts[6]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this <see cref="Car"/> is any different from the provided <see cref="Car" />.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">The <see cref="Car"/> to check against</param>
|
||||||
|
/// <returns>
|
||||||
|
/// <c>true</c> if the specified other is changed; otherwise, <c>false</c>.
|
||||||
|
/// </returns>
|
||||||
public bool IsChanged(Car other)
|
public bool IsChanged(Car other)
|
||||||
{
|
{
|
||||||
return make != other.make || model != other.model || year != other.year || color != other.color || mileage != other.mileage || price != other.price || other.color != color;
|
return this.Make != other.Make || this.Model != other.Model || this.Year != other.Year || this.Color != other.Color || this.Mileage != other.Mileage || this.Price != other.Price || this.Color != other.Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clones this instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An identical but seperate <see cref="Car"/></returns>
|
||||||
public Car Clone()
|
public Car Clone()
|
||||||
{
|
{
|
||||||
return new Car(id, make, model, year, color, mileage, price);
|
return new Car(this.Id, this.Make, this.Model, this.Year, this.Color, this.Mileage, this.Price);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user