Files
carmanager-3/CarManagerV2/Car.cs
2025-09-18 08:34:06 +02:00

61 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarManagerV2
{
public class Car
{
int id;
string make;
string model;
int year;
string color;
int mileage;
decimal price;
public Car(int id, string make, string model, int year, string color, int mileage, decimal price)
{
this.id = id;
this.make = make;
this.model = model;
this.year = year;
this.color = color;
this.mileage = mileage;
this.price = price;
}
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 override string ToString()
{
return $"{make} {model} ({year})";
}
public string toCsvString()
{
return $"{id};{make};{model};{year};{color};{mileage};{price}";
}
public static Car fromCsvString(string csv)
{
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]));
}
public bool isChanged(Car other)
{
return make != other.make || model != other.model || year != other.year || color != other.color || mileage != other.mileage || price != other.price;
}
}
}