public Car AddCar() { string usedOrNew = Validator.UsedChoiceValidator("Is the car you want to add new, or used? (Please enter \"new\" or \"used\")", "That wasn't \"new\" or \"used\". Please enter one of those choices."); if (usedOrNew.ToLower() == "new") { Car temp = new Car(); temp.Make = Validator.MakeValidator("Please enter the make of the car (eg. Ford):", "Sorry, that was an invalid input. Please enter the make of the car (eg. Ford):"); temp.Model = Validator.ModelValidator("Please enter the model of the car (eg. F150):", "Sorry, that was an invalid input. Please enter the model of the car (eg. F150):"); temp.Year = Validator.YearValidator("Please enter the year of the car (eg. 2005):", "Sorry, that is not a valid year. Please enter the year of the car (1900 to 2019):"); temp.Price = Validator.PriceValidator("Please enter the price of the car:", "Not a valid price. Please enter the price of the car."); return(temp); } else { UsedCar temp = new UsedCar(); temp.Make = Validator.MakeValidator("Please enter the make of the car (eg. Ford):", "Sorry, that was an invalid input. Please enter the make of the car (eg. Ford):"); temp.Model = Validator.ModelValidator("Please enter the model of the car (eg. F150):", "Sorry, that was an invalid input. Please enter the model of the car (eg. F150):"); temp.Year = Validator.YearValidator("Please enter the year of the car (eg. 2005):", "Sorry, that is not a valid year. Please enter the year of the car (1900 to 2019):"); temp.Price = Validator.PriceValidator("Please enter the price of the car:", "Not a valid price. Please enter the price of the car."); temp.Mileage = Validator.MileageValidator("Please enter the mileage on the used car.", "Not a valid mileage, please enter the mileage of the used car."); return(temp); } }
static void Main(string[] args) { List <Car> cars = new List <Car>(); UsedCar Seymour = new UsedCar("Subaru", "Legacy", 2000, 1400, 168000); UsedCar Maggie = new UsedCar("Chrystler", "Town and Country", 2002, 1800, 180000); UsedCar Van = new UsedCar("Chevy", "G20", 1985, 1500, 80000); Car Dart = new Car("Dodge", "Dart", 2019, 15000); Car Fit = new Car("Honda", "Fit", 2017, 9000); Car Bronco = new Car("Ford", "Bronco", 2018, 8000); cars.Add(Dart); cars.Add(Fit); cars.Add(Bronco); cars.Add(Seymour); cars.Add(Maggie); cars.Add(Van); Console.WriteLine("Cars Avalable: "); int num = cars.Count; for (int i = 0; i < num; i++) { Console.WriteLine((i + 1) + ". " + cars[i]); } Console.WriteLine(); Console.WriteLine("Which car would you like (enter 1-" + num + ")"); int buy = intParse() - 1; Console.WriteLine(cars[buy]); Console.WriteLine("Would you like to buy this car? (enter y/n)"); bool a = true; while (a == true) { string answer = Console.ReadLine(); if (answer.ToLower().Trim() == "y") { cars.Remove(cars[buy]); Console.WriteLine("Excelent! Our finance department will be with you shortly."); break; } else if (answer.ToLower().Trim() == "n") { break; } else { Console.WriteLine("I'm sorry, I don't understand that answer. Please try answering \"y\" or\"n\"."); continue; } } Console.WriteLine(); Console.WriteLine("Cars Avalable: "); num = cars.Count; for (int i = 0; i < num; i++) { Console.WriteLine((i + 1) + ". " + cars[i]); } Console.WriteLine("Goodbye!"); Console.ReadKey(); }
static void Main(string[] args) { Car1 c1 = new Car1("Chevy", "Equanox", "2015", 20000); Console.WriteLine("How many cars would you like to enter?"); int size = int.Parse(Console.ReadLine()); List <Cars> cars = new List <Cars>(); Cars.Add(new Cars() { MAKE = "Chevy", MODEL = "Equanox", YEAR = "2000", PRICE = 2599 }); Cars.Add(new Cars() { MAKE = "Ford", MODEL = "Edge", YEAR = "2020", PRICE = 2599 }); Cars.Add(new Cars() { MAKE = "GM", MODEL = "Terrain", YEAR = "1998", PRICE = 2599 }); UsedCar.Add(new UsedCar() { MAKE = "Plymouth", MODEL = "Acclaim", YEAR = "1934", PRICE = 2599, MILEAGE = 343000 }); UsedCar.Add(new UsedCar() { MAKE = "Jeep", MODEL = "Wrangler", YEAR = "1994", PRICE = 2599, MILEAGE = 145000 }); UsedCar.Add(new UsedCar() { MAKE = "Saturn", MODEL = "SL1", YEAR = "1999", PRICE = 2599, MILEAGE = 237000 }); // used to add new cars to the list while (true) #region User Input Car Info { //Cars temp = new Cars(); Console.WriteLine("Please provide the make"); string MAKE = Console.ReadLine(); Console.WriteLine("Please provide the car model"); string MODEL = Console.ReadLine(); Console.WriteLine("Please provide car year"); string YEAR = (Console.ReadLine()); Console.WriteLine("Please provide the MSRP"); int PRICE = int.Parse(Console.ReadLine()); Cars temp = new Cars(MAKE, MODEL, YEAR, PRICE); ////practice this *************************** cars.Add(temp); // add the temp object to cars list Console.WriteLine("do you want to add another vehicle?"); string choice = Console.ReadLine(); if (choice == "n") { break; } #endregion #region Print Each Car Info } foreach (Cars c in cars) { Console.WriteLine("Make: " + c.MAKE); Console.WriteLine("Model: " + c.MODEL); Console.WriteLine("Year: " + c.YEAR); Console.WriteLine("Price:" + c.PRICE); Console.WriteLine("========================"); } #endregion #region //Reference Comments//(ignore) //REFERENCE COMMENTS: //Console.WriteLine(john.FirstName); // will display John //john.Salary = 50000; //john.Salary = john.Salary + 10000; //Console.WriteLine(john.Salary); //Console.WriteLine(john.SSN); // blank if unassigned, default filled in. //Employee jacob = new Employee(); //jacob.FirstName = "Jacob"; //jacob.LastName = "Snover"; //jacob.Salary = 250000; #endregion }
static void Main(string[] args) { Car car1 = new Car("Ford", "Fusion", 2013, 19800); Car car2 = new Car("Toyota", "Prius", 2018, 24370); Car car3 = new Car("Dodge", "Durango", 2016, 22100); UsedCar used1 = new UsedCar("Ford", "F150", 2004, 7300, 76405.2); UsedCar used2 = new UsedCar("Hyundai", "Sonata", 2011, 6700, 67130); UsedCar used3 = new UsedCar("Ford", "Flex", 2013, 16400, 24607); List <Car> cars = new List <Car>() { car1, car2, car3, used1, used2, used3 }; CarLot carLot = new CarLot(cars); while (true) { Console.WriteLine($"#: {"Year",-15}{"Model",-15}{"Make",-15}{"Price",-15}{"Mileage (When used)"}"); Console.WriteLine("================================================================================="); carLot.ListCars(cars); while (true) { string addBuyReplace = Validator.AddBuyReplaceValidator("Would you like to add a car to the list, replace a car, or buy a car? (Please enter 'add', 'replace', or 'buy')", "That was not add, buy, or replace. Please enter one of those three options"); if (addBuyReplace.ToLower() == "buy") { int carSelection = Validator.ListChoiceValidator("Select which car you would like: ", $"Not a valid input! Please input between 1 and {carLot.Lot.Count}", $"Not within range. Please enter a number between 1 and {carLot.Lot.Count}", carLot.Lot.Count); Console.WriteLine($"{"Year",-15}{"Model",-15}{"Make",-15}{"Price",-15}{"Mileage (When used)"}"); Console.WriteLine("================================================================================="); Console.WriteLine(carLot.Lot[carSelection - 1].ToString()); string choice = Validator.AddChoiceValidator("Would you like to buy this car? (Y/N): ", "That wasnt a yes or no, so please be clear! Enter (Y/N or yes/no): "); if (choice.ToLower() == "y" | choice.ToLower() == "yes") { carLot.RemoveCar(carSelection); } break; } else if (addBuyReplace.ToLower() == "replace") { int carSelection = Validator.ListChoiceValidator("Select which car you would like to replace: ", $"Not a valid input! Please input between 1 and {carLot.Lot.Count}", $"Not within range. Please enter a number between 1 and {carLot.Lot.Count}", carLot.Lot.Count); Console.WriteLine($"{"Year",-15}{"Model",-15}{"Make",-15}{"Price",-15}{"Mileage (When used)"}"); Console.WriteLine("================================================================================="); Console.WriteLine(carLot.Lot[carSelection - 1].ToString()); carLot.ReplaceCar(cars, carSelection); break; } else { carLot.Lot.Add(carLot.AddCar()); break; } } string continueChoice = Validator.ContinueChoiceValidator("Would you like to see the list of cars?: ", "That wasn't a yes or no, please be clear! Enter (Y/N or yes/no): "); if (continueChoice.ToLower() == "y" | continueChoice.ToLower() == "yes") { Console.Clear(); } else { break; } } Console.ReadKey(); #region AddCarLoop //while (true) //{ // Car temp = new Car(); // temp.Make = Validator.MakeValidator("Please enter the make of the car (eg. Ford):", "Sorry, that was an invalid input. Please enter the make of the car (eg. Ford):"); // temp.Model = Validator.ModelValidator("Please enter the model of the car (eg. F150):", "Sorry, that was an invalid input. Please enter the model of the car (eg. F150):"); // temp.Year = Validator.YearValidator("Please enter the year of the car (eg. 2005):", "Sorry, that is not a valid year. Please enter the year of the car (1900 to 2019):"); // temp.Price = Validator.PriceValidator("Please enter the price of the car:", "Not a valid price. Please enter the price of the car."); // cars.Add(temp); // string choice = Validator.AddChoiceValidator("Would you like to add another car? (Y/N): ", "That wasnt a yes or no, so please be clear! Enter (Y/N or yes/no): "); // if (choice.ToLower() == "n") // break; //} //Console.WriteLine($"{"Year",-15}{"Model",-15}{"Make",-15}{"Price in dollars",-20}"); //Console.WriteLine("============================================================="); //foreach (Car c in cars) //{ // Console.WriteLine(c.ToString()); //} #endregion }
public static void Main(string[] args) { // List of Cars you build List <Car> cars = new List <Car>(); // empty list you're adding to // create objects because not asking for input, and the vars are initialized with data below // can list a string, but will pass an int so user can select vehicle by number on list to get info Car c1 = new Car("Ford", "Focus", 2017, 12000); Car c2 = new Car("Chevy", "Impala", 2017, 15000); Car c3 = new Car("GMC", "Terrain", 2017, 22000); UsedCar u1 = new UsedCar("Cadillac", "XT5", 2017, 35000, 35987.6); UsedCar u2 = new UsedCar("BMW", "i8", 2017, 90000, 50432.8); UsedCar u3 = new UsedCar("Range Rover", "Sport", 2017, 82000, 60342.8); cars.Add(c1); cars.Add(c2); cars.Add(c3); cars.Add(u1); cars.Add(u2); cars.Add(u3); CarLot carlotlist = new CarLot(cars); // create CarList from Car list info while (true) { Console.Clear(); Console.WriteLine("Current Inventory: "); if (carlotlist.Lot.Count() == 0) //newlist, then Class, then listing out the number of availible cars { Console.WriteLine("Sorry, we're sold out!"); } else // if they choose a number of the inventory greater than 0 { foreach (Car c in carlotlist.Lot) // for each listed item that was stored, print info input { Console.WriteLine($"{carlotlist.Lot.IndexOf(c) + 1,1}: {c.Year,-5} {c.Make,-5} {c.Model,-5}"); } Console.WriteLine("================================="); Console.WriteLine("Please choose a vehicle number from the list above: "); } if (carlotlist.Lot.Count() > 0) //if you still have inventory //.count tells how many in the list { try { string input = Console.ReadLine(); foreach (Car c in carlotlist.Lot) // for each listed item that was stored, print info input { if (carlotlist.Lot.IndexOf(c) + 1 == int.Parse(input)) // +1 becaues not index 0 { c.PrintInfo(); Console.WriteLine(); carlotlist.Lot.RemoveAt(int.Parse(input) - 1); } Console.WriteLine("Would you like to view another car, or add a new vehicle to inventory? Choose 'view' or 'add':"); string userChoice = Console.ReadLine(); // takes in user answer of view or add { if (userChoice.ToLower() == "view") { continue; } if (userChoice.ToLower() == "add") { carlotlist.Lot.Insert(int.Parse(input) - 1); } } } } catch (Exception e) { Console.ReadKey();//if no add an exception } } Console.WriteLine("Do you want to view another car? Y/N"); string choice = Console.ReadLine(); if (choice.ToLower() == "n") //so it doesn't matter if it's lower case or uppper case input { break; } Console.Clear(); // print car list method? Console.WriteLine("Current Inventory: "); Console.WriteLine("Make Model Year Price Mileage"); Console.WriteLine("===== ===== ===== ===== ====="); foreach (Car c in carlotlist.Lot) // for each listed item that was stored, print info input { c.PrintInfo(); } } }
public static void Main(string[] args) { // List of Cars you build List <Car> cars = new List <Car>(7); // empty list you're adding to // create objects because not asking for input, and the vars are initialized with data below // can list a string, but will pass an int so user can select vehicle by number on list to get info Car c1 = new Car("Ford", "Focus", 2017, 12000); Car c2 = new Car("Chevy", "Impala", 2017, 15000); Car c3 = new Car("GMC", "Terrain", 2017, 22000); UsedCar u1 = new UsedCar("Cadillac", "XT5", 2017, 35000, 35987.6); UsedCar u2 = new UsedCar("BMW", "i8", 2017, 90000, 50432.8); UsedCar u3 = new UsedCar("Range Rover", "Sport", 2017, 82000, 60342.8); cars.Add(c1); cars.Add(c2); cars.Add(c3); cars.Add(u1); cars.Add(u2); cars.Add(u3); while (true) { Console.Clear(); Console.WriteLine("Current Inventory: "); if (cars.Count() == 0) // no inventory on list { Console.WriteLine("Sorry, we're sold out!"); } else // if they choose a number of the inventory greater than 0 { foreach (Car c in cars) // for each listed item that was stored, print info input { Console.WriteLine($"{cars.IndexOf(c) + 1,1}: {c.Year,-5} {c.Make,-5} {c.Model,-5}"); } Console.WriteLine("================================="); Console.WriteLine("Please choose a vehicle number from the list above: "); } if (cars.Count() > 0) { try { string input = Console.ReadLine(); foreach (Car c in cars) // for each listed item that was stored, print info input { if (cars.IndexOf(c) + 1 == int.Parse(input)) { c.PrintInfo(); Console.WriteLine(); } } } catch (Exception e) { // if no add an exception } } Console.WriteLine("Do you want to view another car? Y/N"); string choice = Console.ReadLine(); if (choice.ToLower() == "n") //so it doesn't matter if it's lower case or uppper case input { break; } Console.Clear(); // print car list method? Console.WriteLine("Current Inventory: "); Console.WriteLine("Make Model Year Price Mileage"); Console.WriteLine("===== ===== ===== ===== ====="); foreach (Car c in cars) // for each listed item that was stored { c.ToString(); } foreach (Car c in cars) // for each listed item that was stored, print info input { c.PrintInfo(); } } }