Example #1
0
        public List <newCar> CSVToCar()
        {
            newCar        ourCar   = new newCar();
            List <string> carList  = new List <string> {
            };
            List <newCar> thisList = new List <newCar> {
            };
            StreamReader sr        = new StreamReader(@"C:\Users\Jason Gardner\Documents\Projects\ClassWork\UsedCarLab\UsedCarLab\CarLotDB.txt");
            string       line      = sr.ReadLine();

            //Hold split values in a string array
            while (line != null)
            {
                carList.Add(line);
                line = sr.ReadLine();
            }

            foreach (string csv in carList)
            {
                string[] thisLine = csv.Split(',');
                //ourCar.make = thisLine[0];
                //ourCar.model = thisLine[1];
                //ourCar.year = Convert.ToInt32(thisLine[2]);
                thisList.Add(new newCar(thisLine[0], thisLine[1], int.Parse(thisLine[2])));
            }

            return(thisList);
        }
Example #2
0
        static void addCar(List <Car> carList)
        {
            string choice;

            do
            {
                Console.WriteLine("Would you like to add a new or used car?");
                choice = Console.ReadLine();
                newCar  thatCar = new newCar();
                usedCar thisCar = new usedCar();
                if (choice == "new")
                {
                    thatCar.makeCar(thatCar);
                    carList.Add(thatCar);
                }
                if (choice == "used")
                {
                    thisCar.makeCar(thisCar);
                    carList.Add(thisCar);
                }
            } while (choice != "no");
        }
Example #3
0
 public static void printList(List <Car> carInventory)
 {
     //writer.WriteLine("New Cars:");
     foreach (Car car in carInventory)
     {
         if (car is newCar)
         {
             newCar thisCar = new newCar();
             thisCar = car as newCar;
             thisCar.CarToCSV();
             Console.WriteLine(thisCar.CSVToCar());
         }
     }
     //writer.WriteLine("Used Cars:");
     foreach (Car car in carInventory)
     {
         if (car is usedCar)
         {
             Console.WriteLine(car.Definition());
             //writer.WriteLine(car.Definition());
         }
     }
     //writer.Close();
 }