Object Oriented Programing

Documented development of a proposed system from concept, to design and finally implementation:

Functions

  1. View shows.
  2. Select a show.
  3. Show seats.
  4. Hold seat.
  5. Buy tickets.

Non-Functions

  • Scalability – The system needs to be able to be built upon and scaled up with further development.
  • Usability – The system needs to be easy for a customer to use and understand without prior experience.
  • Performance – The system needs to not be resource heavy to maintain good performance. (Thus, the code must be optimised well)
  • Security – Data needs to be sensibly handled in such a way that does not compromise the security of the system.

Partial Class Diagram

Psuedocode

:Main

Public main()

{

                Public string customerName;

Public int numOfTickets = 0 ;

Public float totalPrice = 0.0f;

Public float seatPrice = 19.99f;

OBJ

                initialize();

}

Public initialize()

{

                ViewShow();

                If (SelectShow() == true)

                {

                                ViewSeats();

If (SelectSeat() == true)

{

                HoldSeat();

                Initialize();

}

                }

                Else

                {

                                ViewShow();

}              }

:Customer

Public HoldSeat()

{

                numOfTickets++;

                totalPrice += ticketPrice;

}

PurchaseTickets()

{

Console.WriteLine(“You will now be redirected to a webpage where you will be prompted to pay a total of £” + totalPrice + “ to purchase your “ + numOfTickets + “ ticket/s.”)

}

:Show

Public string showName = “Shrek the musical”, showDate = “25th January 2021”, showTime = “17:00”

Public ViewShow()

{

                Console.WriteLine(“The show that you have selected is: “);

                Console.WriteLine(“Name: “ + showName);

                Console.WriteLine(“Date: “ + showDate);

                Console.WriteLine(“Time: “ + showTime);

}

Public bool SelectShow()

{

                Console.WriteLine(“Would you like to view the seating chart for this show? (Y/N)”);

                Private String seeSeats = Console.ReadLine();

                if (seeSeats == “Y” || seeSeats == “y”)

                {

                                Return true;

                }

                else if (seeSeats == “N” || seeSeats == “n”)

                {

                                Return false;

                }

                else

                {

                                Console.WriteLine(“You have entered an incorrect answer”);

                                SelectShow();

}

}

Public ViewSeats()

{

                Public int row = 4, col = 4;

                Public int[,] array = new int[row, col]{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};

                Int rowLength = array.GetLength(0);

                Int colLength = array.GetLength(1);

                for (int i = 0; i < rowLength; i++)

                               {

                                   for (int j = 0; j < colLength; j++)

                                                {

                                                Console.Write(string.Format(“{0} “, array[i, j]));

                                                }

                                Console.Write(Environment.NewLine + Environment.NewLine);

                               }

                Console.ReadLine();

}

:ShowSeat

Public bool SelectSeat()

{

                Console.WriteLine(“If you would like to hold a seat please specify the seats row (1 to 4)”);

                Public int seatRow = Console.ReadLine();

                If (seatRow < 1 || seatRow > 4)

                {

                Console.WriteLine(“Invalid Row number”);

                SelectSeat();

}

                Console.WriteLine(“Next please specify the column the seat was in (1 to 4)”)

                Public int seatCol = Console.ReadLine();

                If (seatCol < 1 || seatCol > 4)

                {

                Console.WriteLine(“Invalid Column number”);

                SelectSeat();

}

                seatRow = seatRow – 1;

                seatCol = seatCol – 1;

                if (CheckTicket() == true)

                {

Return true;

}

Else{

Return false;}}

:Ticket

Public bool CheckTicket()

{

                If (array[seatRow][seatCol] == 99)

                {

                Console.WriteLine(“This seat is already being held, please select another seat.”);

                Return false;

}

Else

{

                Console.WriteLine(“This seat will now be held for you.”)

                Array[seatRow][seatCol] = 99;

Return true;

} }

Implementation

using System;
 
public class Customer
{
    //saves the customer name, only here to show that its information that would be saved.
    public string customerName;
 
    //Variable initialization
    public int numOfTickets = 0;
    public float totalPrice = 0.0f;
    public float seatPrice = 19.99f;
 
    public void HoldSeat()
    {
        //incrementing number of tickets in basket and increasing total cost of basket
        numOfTickets++;
        totalPrice += seatPrice;
    }
 
    public void PurchaseTickets()
    {
        Console.WriteLine("Would you like to pay for your basket, it comes to a total of £" + totalPrice + (" (Y/N)");
        string answer = Console.ReadLine();
 
        if (answer == "Y" || answer == "y")
        {
            //Prompts the user they will be redirected
            Console.WriteLine("You will now be redirected to a webpage where you will be prompted to pay a total of £"
                + totalPrice + " to purchase your " + numOfTickets + "ticket/s.");
        }
    }
}

using System;
using static Customer;
using static ShowSeat;
using static Show;
using static Ticket;

namespace Assignment
{
    class Main0
    {
        static void Main()
        {
            Customer CUST = new Customer();
            ShowSeat SEAT = new ShowSeat();
            Show SHOW = new Show();
            for (int i = 1; i != 0;)
            {
                SHOW.ViewShow();
                if (SHOW.SelectShow() == true)
                {
                    SHOW.ViewSeats();
                    if (SEAT.SelectSeat() == true)
                    {
                        CUST.HoldSeat();
                        CUST.PurchaseTickets();
                    }
                }
                else
                {
                    SHOW.ViewShow();
                }
            }
        }
    }
}


using System;

public class Show
{
    //Initializes variable of the shows details
    public string showName = "Shrek the musical";
    public string showDate = "25th January 2021";
    public string showTime = "17:00";

    public int[,] array = new int[4, 4] { { 01, 02, 03, 04 }, { 05, 06, 07, 08 }, { 09, 10, 11, 12 }, { 13, 14, 15, 16 } };

    public string seeSeats;

    public void ViewShow()
    {
        Console.WriteLine("The details of the show selected are:");
        Console.WriteLine("Name: " + showName);
        Console.WriteLine("Date: " + showDate);
        Console.WriteLine("Time: " + showTime);
    }

    public bool SelectShow()
    {
        Console.WriteLine("Would you like to view the seating chart for this show? (Y/N)");
        seeSeats = Console.ReadLine();

        if (seeSeats == "Y" || seeSeats == "y")
        {
            return true;
        }
        else if (seeSeats == "N" || seeSeats == "n")
        {
            return false;
        }
        else
        {
            Console.WriteLine("You have entered an invalid answer");
            return false;
        }
    }
    public void ViewSeats()
    {
        int rowLength = array.GetLength(0);
        int colLength = array.GetLength(1);
        for (int i = 0; i < rowLength; i++)
        {
            for (int j = 0; j < colLength; j++)
            {
                if (array[i, j] < 10)
                {
                    Console.Write(string.Format(" {0} ", array[i, j]));
                }
                else
                {
                    Console.Write(string.Format("{0} ", array[i, j]));
                }
            }
            Console.Write(Environment.NewLine + Environment.NewLine);
        }
        Console.ReadLine();
    }
}


using System;
using static Ticket;

public class ShowSeat: Ticket
{
    Ticket TICK = new Ticket();

    public bool SelectSeat()
    {
        Console.WriteLine("If you would like to hold a seat please specify the seats row (1 to 4)");
        string seatRow = Console.ReadLine();
        seatRowNum = int.Parse(seatRow);
        if (seatRowNum < 1 || seatRowNum > 4)
        {
            Console.WriteLine("Invalid row number");
            SelectSeat();
        }

        Console.WriteLine("Please specify the column that the seat is in (1 to 4)");
        string seatCol = Console.ReadLine();
        seatColNum = int.Parse(seatCol);
        if(seatColNum < 1 || seatColNum > 4)
        {
            Console.WriteLine("Invalid column number");
            SelectSeat();
        }

        seatRowNum -= 1;
        seatColNum -= 1;

        if (TICK.CheckTicket() == true)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}


using System;
using static Show;

public class Ticket : Show
{
    public int seatRowNum, seatColNum;

	public bool CheckTicket()
    {
        if (array[seatRowNum, seatColNum] == 99)
        {
            Console.WriteLine("This seat is already being held, please select another seat.");
            return false;
        }
        else
        {
            Console.WriteLine("This seat will now be held for you.");
            array[seatRowNum, seatColNum] = 99;
            return true;
        }
    }
}

Test Stratergy

Test No.Input(s)Expected outputActual OutputSuccessful?
1Enter “Y” or “y” to view seating chartSeating chart is displayedSeating chart is displayedY
2Enter “N” or “n” to view seating chartSeating chart is not  displayedSeating chart is displayedY
3Enter something other than “Y” or “N” to view seating chartSeating chart is not displayed, and you are told you have entered an invalid answerSeating chart is not displayed, and you are told you have entered an invalid answerY
4Enter a valid row and column to hold a seat that is availableYou are told the seat is now held by you and are redirectedYou are told the seat is now held by you and are redirectedY
5Enter a valid row and column to hold a seat that is already heldYou are told the seat is already being held and are redirected to choose another seat.You are told the seat is already being held and are redirected to choose another seat.Y
6Enter “Y” or “y” to purchasing ticketsYou are informed that you will be redirected to pay for your tickets, the total price of which is also shown along with the number of tickets.You are informed that you will be redirected to pay for your tickets, the total price of which is also shown along with the number of tickets.Y
7Enter anything else to purchasing ticketsYou are redirected to be shown the details of the selected show and not to pay.You are redirected to be shown the details of the selected show and not to pay.Y

Report

To develop the requirements, it was first a case of examining the brief, this included looking for things like verbs to indicate potential functions. Things that the client actively wants the system to be able to do. These are things like viewing seats or selecting shows for example.

Then I made the non-functions, this was simply a case of identifying the attributes that are important to making the system run smoothly and with minimal complications now, into further development, and the future public use of the system.

For the partial class diagram, I started with the general use suggested classes provided, then adding relevant functions to each of the classes, following this, the attributes. After that I added 3 new classes to the diagram. These being the :User, :Manger and :Agent classes. The latter two are for separate users of the system identified in the brief. The :User class will however be the superclass that all the other specialist classes derive from.

When making pseudocode I write in line with the general gist of the code I will be implementing according to the partial class diagram that I made in the previous part of the assignment. Detailing the contents of the code in the different classes, missing more unimportant things like the “includes”.

For the actual development of the prototype, it was a case of implementing the code that I had written in the pseudocode section of the assignment along with the relevant extra details needed for proper inheritance and object functionality. Then tweaking and changing things in the code until I found optimal solutions that matched the brief well enough and were decently optimized.

To develop the test strategy, it was a case of going through the system and making a note of each way the user could interact5 with the system at each point they could, then listing them with their expected and actual interactions when using the system and marking if the system behaves in response to the users input in the correct way.