feat: display car age

This commit is contained in:
2026-02-23 17:47:01 +01:00
parent 160352383a
commit d733e49698
3 changed files with 89 additions and 12 deletions

View File

@@ -19,6 +19,7 @@ namespace CarManagerV3
private int mileage;
private decimal price;
private int order;
private int age;
public int Id { get => id;
set {
@@ -46,9 +47,7 @@ namespace CarManagerV3
public int Year { get => year;
set
{
if (value < 1886 || value > DateTime.Now.Year + 1) throw new ArgumentException("Year must be between 1886 and next year.");
Console.WriteLine($"Updating year to {year}");
year = value;
}
}
@@ -79,6 +78,19 @@ namespace CarManagerV3
public int Order { get => order; set => order = value; }
public int Age { get => DateTime.Now.Year - year; }
public string AgeString
{
get
{
int age = this.Age;
if (age == 0) return "New";
else if (age == 1) return "1 year";
else if (age < 0) return "From the future!";
else return $"{age} years";
}
}
//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.