static void addTruck(Garage myGarage) { string manufacturer = ""; string model = ""; int modelYear = 0; double initPrice = 0.0; int purchaseDate = 0; double currentOdometer = 0.0; double engineSize = 0.0; double cargoCapacity = 0.0; double towingCapacity = 0.0; getGeneral(ref manufacturer, ref model, ref modelYear, ref initPrice, ref purchaseDate, ref currentOdometer, ref engineSize); getTruck(ref cargoCapacity, ref towingCapacity); try { myGarage.Add(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, cargoCapacity, towingCapacity); Console.WriteLine("\nAdded a small truck\n"); } catch (Exception ex) { Console.WriteLine("\n" + ex.Message + "\n"); } }
static void addMoto(Garage myGarage) { string manufacturer = ""; string model = ""; int modelYear = 0; double initPrice = 0.0; int purchaseDate = 0; double currentOdometer = 0.0; double engineSize = 0.0; string type = ""; getGeneral(ref manufacturer, ref model, ref modelYear, ref initPrice, ref purchaseDate, ref currentOdometer, ref engineSize); getMoto(ref type); try { myGarage.Add(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, type); Console.WriteLine("\nAdded a motorcycle\n"); } catch (Exception ex) { Console.WriteLine("\n" + ex.Message + "\n"); } }
static void showType(Garage myGarage) { string type; Console.WriteLine("Type to display (Motorcycle, Automobile, Small Truck) :"); type = Console.ReadLine(); List<string> tmp = myGarage.Show(type); if (tmp.Count == 0) { Console.WriteLine("No " + type); } else { int counter = 0; foreach (string str in tmp) { if (counter >= 2) { Console.WriteLine("\nPress Enter to continue\n"); Console.ReadLine(); counter = 0; } Console.WriteLine(); Console.WriteLine(str); counter++; } if (counter != 0) { Console.WriteLine("\nPress Enter to Finish\n"); Console.ReadLine(); } } }
static void showModel(Garage myGarage) { int model = 0; Console.WriteLine("Model's year to display :"); while (true) { if (getInputInt(ref model) == true) { break; } else { Console.WriteLine("Invalid input, try entering Model's year again\n"); } } List<string> tmp = myGarage.Show(model); if (tmp.Count == 0) { Console.WriteLine("No vehicles with such model year"); } else { int counter = 0; foreach (string str in tmp) { if (counter >= 2) { Console.WriteLine("\nPress Enter to continue\n"); Console.ReadLine(); counter = 0; } Console.WriteLine(); Console.WriteLine(str); counter++; } if (counter != 0) { Console.WriteLine("\nPress Enter to Finish\n"); Console.ReadLine(); } } }
static void showAll(Garage myGarage) { List<string> tmp = myGarage.Show(); if (tmp.Count == 0) { Console.WriteLine("No vehicles"); } else { int counter = 0; foreach (string str in tmp) { if (counter >= 2) { Console.WriteLine("\nPress Enter to continue\n"); Console.ReadLine(); counter = 0; } Console.WriteLine(); Console.WriteLine(str); counter++; } if (counter != 0) { Console.WriteLine("\nPress Enter to Finish\n"); Console.ReadLine(); } } }
static void modifyOdometer(Garage myGarage) { string vehType; string manufacturer = ""; string model = ""; int modelYear = 0; double initPrice = 0.0; int purchaseDate = 0; double currentOdometer = 0.0; double engineSize = 0.0; string type = ""; int doorNumber = 0; string fuelType = ""; double cargoCapacity = 0.0; double towingCapacity = 0.0; double newOdometer = 0.0; Console.WriteLine("On what vehicle do you want to change the odometer value? Motorcycle, Automobile, Small Truck"); vehType = Console.ReadLine(); getGeneral(ref manufacturer, ref model, ref modelYear, ref initPrice, ref purchaseDate, ref currentOdometer, ref engineSize); if ((vehType == "Motorcycle") || (vehType == "motorcycle")) { getMoto(ref type); int pos = myGarage.Find(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, type); if (pos != -1) { getNewOdometer(ref newOdometer); if (myGarage.ChangeOdometer(pos, newOdometer) == true) { Console.WriteLine("\nChanged\n"); } else { Console.WriteLine("\nInvalud value\n"); } } else { Console.WriteLine("\nNo such Vehicle\n"); } } else if ((vehType == "Automobile") || (vehType == "automobile")) { getAuto(ref doorNumber, ref fuelType); int pos = myGarage.Find(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, doorNumber, fuelType); if (pos != -1) { getNewOdometer(ref newOdometer); if (myGarage.ChangeOdometer(pos, newOdometer) == true) { Console.WriteLine("\nChanged\n"); } else { Console.WriteLine("\nInvalud value\n"); } } else { Console.WriteLine("\nNo such Vehicle\n"); } } else if ((vehType == "Small Truck") || (vehType == "small truck") || (vehType == "Small truck") || (vehType == "small Truck")) { getTruck(ref cargoCapacity, ref towingCapacity); int pos = myGarage.Find(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, cargoCapacity, towingCapacity); if (pos != -1) { getNewOdometer(ref newOdometer); if (myGarage.ChangeOdometer(pos, newOdometer) == true) { Console.WriteLine("\nChanged\n"); } else { Console.WriteLine("\nInvalud value\n"); } } else { Console.WriteLine("\nNo such Vehicle\n"); } } }
static void Main(string[] args) { Garage myGarage = new Garage(); int input = 0; bool exit = false; const string DEFAULT_PATH = "DataBase.txt"; myGarage.LoadDB(DEFAULT_PATH); foreach(string str in args) { myGarage.LoadDB(str); } Console.Clear(); while (exit == false) { ShowMenu(); while (true) { if (getInputInt(ref input) == true) { break; } else { Console.Clear(); Console.WriteLine("Invalid input, try again\n"); ShowMenu(); } } switch (input) { // add moto case 1: { Console.Clear(); addMoto(myGarage); } break; // add auto case 2: { Console.Clear(); addAuto(myGarage); } break; // add truck case 3: { Console.Clear(); addTruck(myGarage); } break; // show all case 4: { Console.Clear(); showAll(myGarage); } break; // show model case 5: { Console.Clear(); showModel(myGarage); } break; // show type case 6: { Console.Clear(); showType(myGarage); } break; // modify odometer case 7: { Console.Clear(); modifyOdometer(myGarage); } break; // delete case 8: { Console.Clear(); delete(myGarage); } break; // exit case 0: { exit = true; myGarage.SaveDB(DEFAULT_PATH); } break; default: { Console.Clear(); Console.WriteLine("Invalid option\n"); } break; } Console.WriteLine(); } }
static void delete(Garage myGarage) { string vehType; string manufacturer = ""; string model = ""; int modelYear = 0; double initPrice = 0.0; int purchaseDate = 0; double currentOdometer = 0.0; double engineSize = 0.0; string type = ""; int doorNumber = 0; string fuelType = ""; double cargoCapacity = 0.0; double towingCapacity = 0.0; Console.WriteLine("What vehicle do you want to delete? Motorcycle, Automobile, Small Truck"); vehType = Console.ReadLine(); getGeneral(ref manufacturer, ref model, ref modelYear, ref initPrice, ref purchaseDate, ref currentOdometer, ref engineSize); if ((vehType == "Motorcycle") || (vehType == "motorcycle")) { getMoto(ref type); int pos = myGarage.Find(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, type); if (pos != -1) { while (true) { Console.WriteLine("Are you sure you want to delete this vehicle?"); string confirm = Console.ReadLine(); if ((confirm == "Yes") || (confirm == "yes") || (confirm == "Y") || (confirm == "y")) { myGarage.Delete(pos, vehType); Console.WriteLine("\nDeleted\n"); break; } else if ((confirm == "No") || (confirm == "no") || (confirm == "N") || (confirm == "n")) { Console.WriteLine("\nCanceled deletion\n"); break; } else { Console.WriteLine("\nInvalid input, try again\n"); } } } else { Console.WriteLine("\nNo such Vehicle\n"); } } else if ((vehType == "Automobile") || (vehType == "automobile")) { getAuto(ref doorNumber, ref fuelType); int pos = myGarage.Find(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, doorNumber, fuelType); if (pos != -1) { while (true) { Console.WriteLine("Are you sure you want to delete this vehicle?"); string confirm = Console.ReadLine(); if ((confirm == "Yes") || (confirm == "yes") || (confirm == "Y") || (confirm == "y")) { myGarage.Delete(pos, vehType); Console.WriteLine("\nDeleted\n"); break; } else if ((confirm == "No") || (confirm == "no") || (confirm == "N") || (confirm == "n")) { Console.WriteLine("\nCanceled deletion\n"); break; } else { Console.WriteLine("\nInvalid input, try again\n"); } } } else { Console.WriteLine("\nNo such Vehicle\n"); } } else if ((vehType == "Small Truck") || (vehType == "small truck") || (vehType == "Small truck") || (vehType == "small Truck")) { getTruck(ref cargoCapacity, ref towingCapacity); int pos = myGarage.Find(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, cargoCapacity, towingCapacity); if (pos != -1) { while (true) { Console.WriteLine("Are you sure you want to delete this vehicle?"); string confirm = Console.ReadLine(); if ((confirm == "Yes") || (confirm == "yes") || (confirm == "Y") || (confirm == "y")) { myGarage.Delete(pos, vehType); Console.WriteLine("\nDeleted\n"); break; } else if ((confirm == "No") || (confirm == "no") || (confirm == "N") || (confirm == "n")) { Console.WriteLine("\nCanceled deletion\n"); break; } else { Console.WriteLine("\nInvalid input, try again\n"); } } } else { Console.WriteLine("\nNo such Vehicle\n"); } } }