public void addAutomobileToContainer(string sManufacturerInfo, string sModelInfo, int nModelYearInfo, double dInitalPurchasePrice, string nPurchaseDateInfo, double dCurrentOdometerInfo, double dSizeOfEngineInfo, int nNumOfDoor, string aFuel, int theYearOfPurchase) { Automobile tempAutomobile = new Automobile(sManufacturerInfo, sModelInfo, nModelYearInfo, dInitalPurchasePrice, nPurchaseDateInfo, dCurrentOdometerInfo, dSizeOfEngineInfo, nNumOfDoor, aFuel, theYearOfPurchase); tempAutomobile.calculateValue(tempAutomobile.PurchasePrice, tempAutomobile.YearPurchased); newVehicles.Add(tempAutomobile); nAutoMobile++; }
/* Method: readDataBase() Description: The purpose of this method is to read from a textfile and store the record member strings into a List template Parameter(s): None Return: Nothing */ public void readDataBase() { int counter = 0; string readLine = ""; try { if (File.Exists("database.txt") == false) { File.Create("database.txt").Dispose(); } System.IO.StreamReader read = new StreamReader("database.txt"); while (true) { readLine = read.ReadLine(); if (readLine == null) { break; } if (readLine[0] == 'M') { counter = 0; string manufacturer = ""; string Model = ""; int ModelYear = 0; double PurchasePrice = 0.0; string PurchaseDate = ""; double CurrentOdometer = 0.0; double SizeOfEngine = 0.0; string TypeOfMotocycle = ""; string[] information = readLine.Split('|'); foreach (string readed in information) { if (nMotocycle > 10) { continue; } if (counter == 1) { manufacturer = readed; } else if (counter == 2) { Model = readed; } else if (counter == 3) { ModelYear = Convert.ToInt32(readed); } else if (counter == 4) { PurchasePrice = Convert.ToDouble(readed); } else if (counter == 5) { PurchaseDate = readed; } else if (counter == 6) { CurrentOdometer = Convert.ToDouble(readed); } else if (counter == 7) { SizeOfEngine = Convert.ToDouble(readed); } else if (counter == 8) { TypeOfMotocycle = readed; } else { } counter++; } Motorcycle createNewMoto = new Motorcycle("M", manufacturer, Model, ModelYear, PurchasePrice, PurchaseDate, CurrentOdometer, SizeOfEngine, TypeOfMotocycle); newVehicles.Add(createNewMoto); nMotocycle++; } else if ((readLine[0] == 'S') && (readLine[1] == 'T')) { counter = 0; string manufacturer = ""; string Model = ""; int ModelYear = 0; double PurchasePrice = 0.0; string PurchaseDate = ""; double CurrentOdometer = 0.0; double cargoSize = 0; double towingCapcity = 0; double SizeOfEngine = 0.0; string[] information = readLine.Split('|'); foreach (string readed in information) { if (nSmallTruck > 10) { continue; } if (counter == 1) { manufacturer = readed; } else if (counter == 2) { Model = readed; } else if (counter == 3) { ModelYear = Convert.ToInt32(readed); } else if (counter == 4) { PurchasePrice = Convert.ToDouble(readed); } else if (counter == 5) { PurchaseDate = readed; } else if (counter == 6) { CurrentOdometer = Convert.ToDouble(readed); } else if (counter == 7) { SizeOfEngine = Convert.ToDouble(readed); } else if (counter == 8) { cargoSize = Convert.ToDouble(readed); } else if (counter == 9) { towingCapcity = Convert.ToDouble(readed); } else { } counter++; } Small_Truck createNewMoto = new Small_Truck(manufacturer, Model, ModelYear, PurchasePrice, PurchaseDate, CurrentOdometer, SizeOfEngine, cargoSize, towingCapcity); newVehicles.Add(createNewMoto); nSmallTruck++; } else if (readLine[0] == 'A') { counter = 0; string manufacturer = ""; string Model = ""; int ModelYear = 0; double PurchasePrice = 0.0; string PurchaseDate = ""; double CurrentOdometer = 0.0; int doorNum = 0; string typeOfFuel = ""; double SizeOfEngine = 0.0; string[] information = readLine.Split('|'); foreach (string readed in information) { if (nAutoMobile > 10) { continue; } if (counter == 1) { manufacturer = readed; } else if (counter == 2) { Model = readed; } else if (counter == 3) { ModelYear = Convert.ToInt32(readed); } else if (counter == 4) { PurchasePrice = Convert.ToDouble(readed); } else if (counter == 5) { PurchaseDate = readed; } else if (counter == 6) { CurrentOdometer = Convert.ToDouble(readed); } else if (counter == 7) { SizeOfEngine = Convert.ToDouble(readed); } else if (counter == 8) { doorNum = Convert.ToInt32(readed); } else if (counter == 9) { typeOfFuel = readed; } else { } counter++; } Automobile temp = new Automobile(manufacturer, Model, ModelYear, PurchasePrice, PurchaseDate, CurrentOdometer, SizeOfEngine, doorNum, typeOfFuel); newVehicles.Add(temp); nAutoMobile++; } else { } } read.Close(); // FileStream fs = new FileStream("database.txt", FileMode.OpenOrCreate); } catch (Exception efs) { Console.WriteLine(efs.Message); } }