using System.Collections.Generic;
public Automobile(string idNumber, string make, int year, int price)
public string IDNumber { get; set; }
public string Make { get; set; }
public int Year { get; set; }
public int Price { get; set; }
public override string ToString()
return "Id Number: " + IDNumber + "Make: " + Make + "Year: " + Year + "Price: " + Price;
public class AutomobileDemo{
public static void Main(string[] args)
List<Automobile> automobiles = new List<Automobile>();
Console.WriteLine("Please enter the details of eight(8) automobiles");
for (var i = 0; i < 8; i++)
Console.WriteLine("Please enter the details of automobile number :" + (i + 1)) ;
var idNumber = string.Empty;
bool isValidEntry = false;
Console.WriteLine("Enter Id Number:");
idNumber = Console.ReadLine();
if (automobiles.Any(s => s.IDNumber == idNumber))
Console.WriteLine("The automobile ID Number you have entered was already existed, please try again");
Console.WriteLine("Make:");
make = Console.ReadLine();
Console.WriteLine("Year:");
isValidEntry = int.TryParse(Console.ReadLine(), out year);
Console.WriteLine("The year you entered is invalid please try again!");
Console.WriteLine("Price:");
isValidEntry = int.TryParse(Console.ReadLine(), out price);
Console.WriteLine("The price you entered is invalid please try again!");
Automobile automobile = new Automobile(idNumber, make, year, price);
automobiles.Add(automobile);
foreach (var automobile in automobiles)
Console.WriteLine("Automobile Number " + automobileCount);
Console.WriteLine(automobile.ToString());
Console.WriteLine("Total Price is " + automobiles.Sum(s=> s.Price));