Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following scenario: A small parking deck has hired you to create a

ID: 3755004 • Letter: C

Question

Consider the following scenario:

A small parking deck has hired you to create a new reservation system. Use a 2 dimensional array to note which spots are reserved for the day. Assume that you only reserve one day at a time.

There are two decks: first floor and second floor.

There are a 6 parking spots on each floor.

There is no elevator, so 2 spots on the first floor are reserved for handicap reservations. Only handicap reservations can be used for those parking spots at Spot 1 and Spot 2. You must determine that that reservation is a handicap reservation in order to book those spots. Only 2 handicap reservations can be accommodated, so verify availability.

There are 2 electric car spots on the first floor; only drivers with electric cars can request one of those parking spots. They are located at Spot 5 and Spot 6

For non-handicap and non electric car reservations, choose the next available spot from remaining spots.

Application Design requirements:

Create a C# application that prompts the user for the reservation type, verifies availability and reserves a parking spot.

For each reservation attempt, you should display a message telling the user that the reservation was “confirmed” or is “Not available” and print out the entire reservation schedule for that day as shown in the example below. You should also have a display option so that the reservation list may be viewed prior to selection of a room.

The reservation should be handled by a class that uses a 2 dimension array. (For example (only):      Array[deck floor][spot number] ).

Example of output screen.

Bob Smith IT3883 – Assignment 3

Your reservation Deck 1 Spot 3 is confirmed.

Deck#       Parking Spot Status

1              1                  Open

1              2                  Open

1              3                  Reserved

1              4                  Open

1              5                  Open

2              1                  Open

2              2                  Open

2              3                  Open

2              4                  Open

2              5                  Open

Testing:

     Your application must handle all possibilities correctly not just the specified test case below.   Be sure to include with the following test cases in your screen shot:

Test cases:

1 non electric car non-handicap

1 non electric car non-handicap

1 non electric car handicap

1 non electric car handicap

1 non electric car handicap

1 electric car non-handicap

1 electric car non-handicap

1 electric car non-handicap

1 non electric car non-handicap

1 non electric car non-handicap

Explanation / Answer

ScreenShot

-------------------------------------------------------

Program

using System;
//Booking class
class ReservationSystem
{
    //Member variable is an array for parking space
    string[,] parking = new string[2, 6];
    //Default constructor set all space open
    public ReservationSystem()
    {
        for(int i = 0; i < 2; i++)
        {
            for(int j = 0; j < 6; j++)
            {
                parking[i, j] = "Open";
            }
        }
    }
    //Check availability of a space in parking lot
    public bool availability(int d,int s)
    {
       if(parking[d-1,s-1] == "Open")
        {
            parking[d-1,s-1] = "Reserved";
             return true;
        }
        else
        {
            return false;
        }  
    }
    //Print parking lot details
    public void printArray()
    {
        Console.WriteLine("Deck#     ParkingSpot    Status");
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 6; j++)
            {
               Console.WriteLine(i+1+"           "+(j+1)+"            "+parking[i,j]);
            }
        }
    }
}
//Test method
namespace ReservationSystemMain
{
    class Program
    {
        static void Main(string[] args)
        {
            //Reservation system class object
            ReservationSystem rs = new ReservationSystem();
            //Variables for input
            bool ch = true;
            char hc,choice;
            int spot = 0, deck = 0;
            //Welcome message
            Console.WriteLine("                       Welcome To Parking Reservation System ");
            //Loop until false
            while (ch == true)
            {
                //Prompt for deck number
                Console.Write("Please enter the Deck you want to book(1-2):");
                deck =Convert.ToInt32(Console.ReadLine());
                //Error check
                while (deck<1 || deck>2)
                {
                    Console.WriteLine("You entered wrong deck number.Please enter either 1 or 2!!!!");
                    Console.Write("Please enter the Deck you want to book(1-2):");
                    deck = Convert.ToInt32(Console.ReadLine());
                }
                //Prompt for spot
                Console.Write("Please enter the Spot you want to book(1-6):");
                spot = Convert.ToInt32(Console.ReadLine());
                //Error check
                while (spot < 1 || spot > 6)
                {
                    Console.WriteLine("You entered wrong spot number.Please enter from 1 to 6!!!!");
                    Console.Write("Please enter the Spot you want to book(1-6):");
                    spot = Convert.ToInt32(Console.ReadLine());
                }
                //If requested space for handicap check
                if(deck==1 && spot == 1 || spot == 2)
                {
                    Console.Write("Are you handicap(y/n): ");
                    hc = Console.ReadKey().KeyChar;
                    if (hc == 'y' || hc == 'Y')
                    {
                        if(rs.availability(deck, spot))
                        {
                            Console.WriteLine(" Your reservation Deck "+deck+" Spot "+spot+" is confirmed.");
                            rs.printArray();
                        }
                        else
                        {
                            Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is not available.");
                            rs.printArray();
                        }
                    }
                    else
                    {
                        Console.WriteLine(" This Spot reserved for handicap only!!!!");
                        rs.printArray();
                    }
                }
                //If requested space for electric car check
                else if (deck == 1 && (spot == 3 || spot == 4))
                {
                    Console.Write("Car is electric(y/n): ");
                    char el = Console.ReadKey().KeyChar;
                    if (el == 'y' || el == 'Y')
                    {
                        if(rs.availability(deck, spot))
                        {
                            Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is confirmed.");
                            rs.printArray();
                        }
                        else
                        {
                            Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is not available.");
                            rs.printArray();
                        }
                    }
                    else
                    {
                        Console.WriteLine(" This Spot reserved for electric cars only!!!!");
                        rs.printArray();
                    }
                }
                //Others
                else
                {
                    Console.Write(" Are you handicap(y/n): ");
                    hc = Console.ReadKey().KeyChar;
                    Console.Write(" Car is electric(y/n): ");
                    char el = Console.ReadKey().KeyChar;
                    //Handicap and non electric
                    if((hc=='y'||hc=='Y') && (el=='n' || el == 'N'))
                    {
                        if (deck == 2)
                        {
                            Console.WriteLine("There is no elevator.So not allowed for handicap.");
                        }
                        else
                        {
                            if (rs.availability(1, 1))
                            {
                                Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is confirmed.");
                                rs.printArray();
                            }
                            else if (rs.availability(1, 2))
                            {
                                Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is confirmed.");
                                rs.printArray();
                            }
                            else
                            {
                                Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is not for handicap.");
                            }

                        }
                    }
                    //Non Handicap and electric
                    else if ((hc == 'n' || hc == 'N') && (el == 'y' || el == 'y'))
                    {
                        if (deck == 2)
                        {
                            Console.WriteLine("Not allowed for electric cars.");
                        }
                        else
                        {
                            if (rs.availability(1, 3))
                            {
                                Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is confirmed.");
                                rs.printArray();
                            }
                            else if (rs.availability(1, 4))
                            {
                                Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is confirmed.");
                                rs.printArray();
                            }
                            else
                            {
                                Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is not for electric cars.");
                            }

                        }
                    }
                    //Normal booking
                    else if ((hc == 'n' || hc == 'N') && (el == 'n' || el == 'N'))
                    {
                        if (rs.availability(deck, spot))
                        {
                            Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is confirmed.");
                            rs.printArray();
                        }
                        else
                        {
                            Console.WriteLine(" Your reservation Deck " + deck + " Spot " + spot + " is not available.");
                            rs.printArray();
                        }
                    }
                  
                }
                //Prompt for continue book
                Console.Write("Do you want to continue booking(y/n): ");
                choice = Console.ReadKey().KeyChar;
                if (choice == 'y' || choice == 'Y')
                {
                    ch = true;
                }
                else
                {
                    ch = false;
                }
                Console.WriteLine();
            }
            //End of the program
            Console.WriteLine("Enjoy Your Day!!!!!");
        }
    }
}

Output

                       Welcome To Parking Reservation System

Please enter the Deck you want to book(1-2):1
Please enter the Spot you want to book(1-6):5

Are you handicap(y/n): n
Car is electric(y/n): n
Your reservation Deck 1 Spot 5 is confirmed.
Deck#     ParkingSpot    Status
1           1            Open
1           2            Open
1           3            Open
1           4            Open
1           5            Reserved
1           6            Open
2           1            Open
2           2            Open
2           3            Open
2           4            Open
2           5            Open
2           6            Open
Do you want to continue booking(y/n): n

Enjoy Your Day!!!!!
Press any key to continue . . .

Note

Due to space restriction,i can't upload full output.