Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp2
- {
- public class Car
- {
- public string make { get; set; }
- public int price { get; set; }
- public int year { get; set; }
- public Car()
- {
- make = "empty";
- price = 0;
- year = 0;
- }
- public Car(string a, int b, int c)
- {
- make = a;
- price = b;
- year = c;
- }
- }
- public class AllCars
- {
- public List<Car> CarList { get; set; }
- public AllCars()
- {
- CarList = new List<Car>();
- }
- public int Price_Average()
- {
- int total_price = 0;
- int average_price = 0;
- foreach (var i in CarList)
- {
- total_price += i.price;
- }
- average_price = total_price / CarList.Count;
- return average_price;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Car a = new Car("Aston Martin", 50000, 2012);
- Car b = new Car("BMW", 30000, 2014);
- Car c = new Car("Cheverolet", 20000, 2013);
- Car d = new Car("Datsun", 2000, 2001);
- AllCars all = new AllCars();
- all.CarList.Add(a);
- all.CarList.Add(b);
- all.CarList.Add(c);
- all.CarList.Add(d);
- int total_price_average = all.Price_Average();
- Console.WriteLine("The avearge Car Price is " + total_price_average);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement