Exemple #1
0
      public static void AddUsedCar()
      {
          Console.WriteLine("Enter the manufacturer of the car: ");
          string manufacturer = Console.ReadLine();

          Console.WriteLine("Enter the make of the car: ");
          string group = Console.ReadLine();

          Console.WriteLine("Enter the year the car was made (ex. 2014): ");
          string modelYear  = Console.ReadLine();
          int    model_Year = int.Parse(modelYear);

          Console.WriteLine("Enter the price for the car: ");
          string newPrice  = Console.ReadLine();
          double new_Price = double.Parse(newPrice);

          Console.WriteLine("Enter the car's mileage: ");
          string miles  = Console.ReadLine();
          double miles_ = double.Parse(miles);

          UsedCar usedAddition = new UsedCar(manufacturer, group, model_Year, new_Price, miles_);
      }
Exemple #2
0
      static void Main()
      {
          Car     tesla       = new Car("Tesla", "Cybertruck", 2020, 35000);
          Car     bronco      = new Car("Ford", "Bronco", 2020, 50000);
          Car     viper       = new Car("Dodge", "Viper", 2020, 45000);
          UsedCar ford        = new UsedCar("Ford", "Focus RS", 2016, 25000, 75000);
          UsedCar toyota      = new UsedCar("Toyota", "Prius", 2012, 15000, 10000);
          UsedCar koeniggsegg = new UsedCar("Koeniggsegg", "Agera", 2016, 100000, 75000);

          int number = 0;

          Console.WriteLine("Welcome to the Car Lot!");

          do
          {
              CarLot.CarInventory();
              Console.WriteLine($"{CarLot.Cars.Count + 1}. Add a car");
              Console.WriteLine($"{CarLot.Cars.Count + 2}. Quit");
              Console.WriteLine("");
              Console.WriteLine("Which car would you like to purchase?");

              string entry = Console.ReadLine();
              if (!int.TryParse(entry, out number))
              {
                  Console.WriteLine("Please have a valid input next time.");
              }

              if (number < CarLot.Cars.Count + 1)
              {
                  Console.WriteLine(CarLot.Cars[number - 1].Make);
                  Console.WriteLine("Confirm purchase? 'Y' to confirm, else any other value to cancel.");
                  string yn = Console.ReadLine().ToLower();
                  if (yn == "y")
                  {
                      Console.WriteLine("You have succesfully purchased the " + CarLot.Cars[number - 1].Make);
                      CarLot.RemoveCar(number - 1);
                  }
              }
              else if (number == CarLot.Cars.Count + 1)
              {
                  Console.WriteLine("Is this a new or used car?");
                  while (true)
                  {
                      string NewUsed = Console.ReadLine().ToLower();
                      if (NewUsed == "new")
                      {
                          //Call seperate Method to Add New Car to list.
                          CarLot.AddNewCar();
                          break;
                      }
                      else if (NewUsed == "used")
                      {
                          //Call seperate Method to Add Used Car to list.
                          UsedCar.AddUsedCar();
                          break;
                      }
                      else
                      {
                          Console.WriteLine("Please enter new or used.");
                      }
                  }
              }
              else if (number == CarLot.Cars.Count + 2)
              {
                  Quit();
              }
              else
              {
                  Console.WriteLine("Not a valid input.");
              }
          }while (Quit());
      }