Exemplo n.º 1
0
 public static void FindSpot(Vehicles vehicle)
 {
     if (vehicle.Size == 1)
     {
         foreach (Level level in ParkingStructure.Structure)
         {
             foreach (ParkingSpot spot in level.SpotArray)
             {
                 if (spot.Open)
                 {
                     spot.Open = false;
                     Console.WriteLine("Your Vehicle is on Level {0} and in spot {1}.", level.FloorNumber, spot.SpotNumber);
                     return;
                 }
             }
         }
         Console.WriteLine("Sorry there are no open spots");
         return;
     }
     else if (vehicle.Size == 2)
     {
         foreach (Level level in ParkingStructure.Structure)
         {
             foreach (ParkingSpot spot in level.SpotArray)
             {
                 if (spot.Open && spot.Size >= 2)
                 {
                     spot.Open = false;
                     Console.WriteLine("Your Vehicle is on Level {0} and in spot {1}.", level.FloorNumber, spot.SpotNumber);
                     return;
                 }
             }
         }
         Console.WriteLine("Sorry there are no open spots");
         return;
     }
     else
     {
         foreach (Level level in ParkingStructure.Structure)
         {
             foreach (ParkingSpot spot in level.SpotArray)
             {
                 if (spot.Open && spot.Size == 3)
                 {
                     bool inRow = true;
                     int  i     = spot.SpotNumber;
                     while (inRow == true && i <= spot.SpotNumber + 3)
                     {
                         if (!level.SpotArray[i].Open == true || level.SpotArray[i].Size != 3)
                         {
                             inRow = false;
                         }
                         if (i == spot.Size + 3)
                         {
                             Console.WriteLine("Your Vehicle is on Level {0} and in spots {1} - {2}.", level.FloorNumber, spot.SpotNumber, spot.SpotNumber + 4);
                             return;
                         }
                         i++;
                     }
                 }
             }
         }
         Console.WriteLine("Sorry there are no open spots");
         return;
     }
 }
Exemplo n.º 2
0
 //This is the main logic of the program.  The chosen Vehicles object is passed in.
 public static void FindSpot(Vehicles vehicle)
 {
     //If the vehicle is a motorcycle
     if (vehicle.Size == 1)
     {
         foreach (Level level in ParkingStructure.Structure)
         {
             foreach (ParkingSpot spot in level.SpotArray)
             {
                 if (spot.Open)
                 {
                     //The parking spot will be marked as taken
                     spot.Open = false;
                     Console.WriteLine("Your Vehicle is on Level {0} and in spot {1}.", level.FloorNumber, spot.SpotNumber);
                     return;
                 }
             }
         }
         //Inform the user if there is no open spot
         Console.WriteLine("Sorry there are no open spots for your vehicle");
         return;
     }
     //If the vehicle is a compact
     else if (vehicle.Size == 2)
     {
         foreach (Level level in ParkingStructure.Structure)
         {
             foreach (ParkingSpot spot in level.SpotArray)
             {
                 if (spot.Open && spot.Size >= 2)
                 {
                     spot.Open = false;
                     Console.WriteLine("Your Vehicle is on Level {0} and in spot {1}.", level.FloorNumber, spot.SpotNumber);
                     return;
                 }
             }
         }
         Console.WriteLine("Sorry there are no open spots for your vehicle");
         return;
     }
     //If the vehicle is a bus
     else if (vehicle.Size == 3)
     {
         foreach (Level level in ParkingStructure.Structure)
         {
             foreach (ParkingSpot spot in level.SpotArray)
             {
                 if (spot.Open && spot.Size == 3)
                 {
                     //Check to see if 5 parking spots in a row are open and are large spots
                     bool inRow = true;
                     int  i     = spot.SpotNumber;
                     while (inRow == true && i <= spot.SpotNumber + 3 && i < level.SpotArray.Length)
                     {
                         if (!level.SpotArray[i].Open == true || level.SpotArray[i].Size != 3)
                         {
                             inRow = false;
                         }
                         if (i == spot.Size + 3)
                         {
                             Console.WriteLine("Your Vehicle is on Level {0} and in spots {1} - {2}.", level.FloorNumber, spot.SpotNumber, spot.SpotNumber + 4);
                             //Mark all 5 spots as taken
                             for (int j = spot.SpotNumber - 1; j <= spot.SpotNumber + 3; j++)
                             {
                                 level.SpotArray[j].Open = false;
                             }
                             return;
                         }
                         i++;
                     }
                 }
             }
         }
         Console.WriteLine("Sorry there are no open spots for your vehicle");
         return;
     }
 }