示例#1
0
        static void Main(string[] args)
        {
            //List of car models and types
            Console.WriteLine("Welcome to the Grand Circus Car Lot! Here is your list of cars you may buy:");

            Console.WriteLine("Make".PadRight(8, ' ') + "\t" + "Model".PadRight(8, ' ') + "\t" + "Year".PadRight(8, ' ') + "\t" + "Price".PadRight(8, ' ') + "\t" + "Miles");

            Car c1 = new Car("1. Nikkolai", "Model S", 2017, 54999.90);

            Car c2 = new Car("2. Fourd", "Escapade", 2017, 31999.90);

            Car c3 = new Car("3. Chewie", "Vette", 2017, 44989.95);

            UsedCar u1 = new UsedCar("4. Hyonda", "Prior", 2015, 14795.50, 35987.6);

            UsedCar u2 = new UsedCar("5. GC", "Chirpus", 2013, 8500.00, 12345.0);

            UsedCar u3 = new UsedCar("6. GC", "Witherell", 2016, 14450.00, 3500.3);



            Car[] InventoryList = new Car[6]; //array of Inventory

            InventoryList[0] = c1;
            InventoryList[1] = c2;
            InventoryList[2] = c3;

            InventoryList[3] = u1; // polymorphism
            InventoryList[4] = u2; // polymorphism
            InventoryList[5] = u3; // polymorphism
            //InventoryList[6] = Console.WriteLine("6. Quit"); ??

            for (int i = 0; i < InventoryList.Length; i++)
            {
                Console.WriteLine(InventoryList[i].ToString()); //print override info from UsedCar and Car
                //you can even write this without ToString Method, because the compiler will automatically do this for the printing of the object.
            }
            Console.WriteLine("7. Quit");

            Console.WriteLine("Which car would you like?");
            int CarChoice = int.Parse(Console.ReadLine());

            CarChoice = CarChoice - 1;
            if (CarChoice == InventoryList.Length)
            {
                Console.WriteLine("Goodbye!");
            }

            else
            {
                //Console.WriteLine(InventoryList[CarChoice].Make);
                //validate input is only 1-6
                InventoryList[CarChoice].PrintInfo(); //can also be done with ToString
            }
            //to remove from list:
            //int indexToRemove = int.Parse(Console.ReadLine());
            //InventoryList = InventoryList.Where((source, index) => index != indexToRemove).ToArray(); (insert above)
        }
示例#2
0
 private static void IntantiateObjects(out Car car1, out Car car2, out Car car3, out UsedCar car4, out UsedCar car5, out UsedCar car6)
 {
     //Instantiate
     car1 = new Car("Nikolai", "Model S", 2017, 54999.90);
     car2 = new Car("Fourd", "Escapade", 2017, 31999.90);
     car3 = new Car("Chewie", "Vette", 2017, 44989.95);
     car4 = new UsedCar("Hyonda", "Prior", 2015, 14795.5, 35987);
     car5 = new UsedCar("GC", "Chirpus", 2013, 8500, 12345);
     car6 = new UsedCar("GC", "Witherell", 2016, 14450, 3500);
 }
示例#3
0
        public static List <Car> MakeLot()
        {
            Car car1 = new UsedCar("Toyota", "Prius", 2008, 10000, 100000);
            Car car2 = new UsedCar("Hyandai", "Santa Fe", 2007, 11200, 200000);
            Car car3 = new Car("Chevy", "Cobalt", 2009, 45000);
            Car car4 = new Car("Chevy", "Mustang", 2018, 99000);
            Car car5 = new Car("Jeep", "Wrangler", 2015, 60600);
            Car car6 = new UsedCar("Chevrolet", "Cavalier", 2001, 2000, 300000);

            List <Car> carLot = new List <Car>()
            {
                car1, car2, car3, car4, car5, car6
            };

            return(carLot);
        }