Add project files.
This commit is contained in:
56
CarManagerV2/Car.cs
Normal file
56
CarManagerV2/Car.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
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.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)
|
||||
{
|
||||
Console.WriteLine(csv);
|
||||
string[] parts = csv.Split(';');
|
||||
Console.WriteLine(parts.Length);
|
||||
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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user