예제 #1
0
        public void RemoveHouse()
        {
            int selection;

            do
            {
                Console.Clear();
                int numHouses = ViewHouses();
                Console.WriteLine("\nWhich house would you like to remove? (Enter the number, or ESC to cancel)\n");
                keyPressed = Console.ReadKey(true);
                if (Validate.IsEscape(keyPressed)) // user pressed the ESC key
                {
                    return;
                }
                selection = Validate.Range(keyPressed, 1, numHouses);
                if (selection != -1)
                {
                    House house = myHouses.ElementAt(selection - 1);
                    myHouses.Remove(house);
                    Console.Clear();
                    Console.WriteLine("\nHouse #" + selection + " has been condemned because it is infested with rabid wombats.\n\n");
                    ViewHouses();
                }
            }while (selection == -1);
        }
예제 #2
0
 public void AddCars()
 {
     do
     {
         Console.Clear();
         Car car = new Car();
         int retVal;
         do
         {
             Console.WriteLine("Enter the year: ");
             car.year = Console.ReadLine();
             retVal   = (int)Validate.Range(car.year, 1900, DateTime.Now.Year);
         } while (retVal == -1);
         Console.WriteLine("Enter the make: ");
         car.make = Console.ReadLine();
         Console.WriteLine("Enter the model: ");
         car.model = Console.ReadLine();
         myCars.Add(car);
         do
         {
             Console.WriteLine("Would you like to add another car? (Y/N)");
             keyPressed = Console.ReadKey(true);
         } while (!Validate.IsYesNo(keyPressed));
     } while (keyPressed.Key == ConsoleKey.Y);
 }
예제 #3
0
        public void RemoveCar()
        {
            int selection;

            do
            {
                Console.Clear();
                int numCars = ViewCars();
                Console.WriteLine("Which car would you like to remove? (Enter the number, or ESC to cancel)\n");
                keyPressed = Console.ReadKey(true);
                if (Validate.IsEscape(keyPressed)) // user pressed the ESC key
                {
                    return;
                }
                selection = Validate.Range(keyPressed, 1, numCars);
                if (selection > -1)
                {
                    Car car = myCars.ElementAt(selection - 1);
                    myCars.Remove(car);
                    Console.Clear();
                    Console.WriteLine("\nCar #" + selection + " is gone because it has been eaten by wombats.\n\n");
                    ViewCars();
                }
            }while (selection == -1);
        }
예제 #4
0
        public void AddHouse()
        {
            do
            {
                House house = new House();
                int   selection;

                do
                {
                    Console.Clear();
                    Console.WriteLine("\nWhat type of house would you like to enter (1 or 2):\n");
                    Console.WriteLine("1. Single Family Residence");
                    Console.WriteLine("2. Townhome or Condo\n\n");
                    selection = Validate.Range(Console.ReadKey(true), 1, 2);
                    switch (selection)
                    {
                    case 1:
                        house.type = "Single Family Residence";
                        break;

                    case 2:
                        house.type = "Apartment or Condo";
                        break;
                    }
                } while (selection == -1);

                bool    retVal;
                decimal result;
                do
                {
                    Console.WriteLine("\nHow many bedrooms?");
                    house.bedrooms = Console.ReadLine();
                    retVal         = Validate.IsNumber(house.bedrooms, out result);
                } while (!retVal);
                do
                {
                    Console.WriteLine("\nHow many bathrooms?");
                    house.bathrooms = Console.ReadLine();
                    retVal          = Validate.IsNumber(house.bathrooms, out result);
                } while (!retVal);
                do
                {
                    Console.WriteLine("\nEnter the square footage:");
                    house.sqft = Console.ReadLine();
                    retVal     = Validate.IsNumber(house.sqft, out result);
                } while (!retVal);

                myHouses.Add(house);

                do
                {
                    Console.WriteLine("\nEnter another house? (Y/N)\n");
                    keyPressed = Console.ReadKey(true);
                } while (!Validate.IsYesNo(keyPressed));
            } while (keyPressed.Key == ConsoleKey.Y);
        }
예제 #5
0
        static void Main(string[] args)
        {
            ConsoleKeyInfo keyPressed;
            Garage         myGarage     = new Garage();
            RealEstate     myRealEstate = new RealEstate();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Please select from the choices below:\n");
                Console.WriteLine("-------------------------------------");
                Console.WriteLine("  1.  Add real estate listings");
                Console.WriteLine("  2.  View real estate listings");
                Console.WriteLine("  3.  Remove a listing");
                Console.WriteLine("  4.  Add cars to garage");
                Console.WriteLine("  5.  View garage contents");
                Console.WriteLine("  6.  Remove a car");
                Console.WriteLine("  7.  Exit");

                keyPressed = Console.ReadKey(true);

                int selection = Validate.Range(keyPressed, 1, 7);

                switch (selection)
                {
                case 1:
                    Console.Clear();
                    myRealEstate.AddHouse();
                    break;

                case 2:
                    Console.Clear();
                    myRealEstate.ViewHouses();
                    Console.WriteLine("\n\nPress any key to return to the Main Menu...");
                    Console.ReadKey(true);
                    break;

                case 3:
                    Console.Clear();
                    myRealEstate.RemoveHouse();
                    Console.WriteLine("\n\nPress any key to return to the Main Menu...");
                    Console.ReadKey(true);
                    break;

                case 4:
                    Console.Clear();
                    myGarage.AddCars();
                    break;

                case 5:
                    Console.Clear();
                    myGarage.ViewCars();
                    Console.WriteLine("\n\nPress any key to return to the Main Menu...");
                    Console.ReadKey(true);
                    break;

                case 6:
                    Console.Clear();
                    myGarage.RemoveCar();
                    Console.WriteLine("\n\nPress any key to return to the Main Menu...");
                    Console.ReadKey(true);
                    break;

                case 7:
                    return;
                }
            }
        }