This task is designed to evaluate your practical understanding of PHP Object-Oriented Programming, array manipulation, and data querying logic. You will work with pre-defined classes and data, simulating a bus booking system without using a database.
You are given a simplified bus booking system. The system consists of:
- A list of buses, each having an ID, name, and total number of seats.
- A list of bookings, where each booking is linked to a bus and contains passenger information and travel date.
This simulation is implemented using basic PHP classes and dummy data stored in arrays. Your task is to interact with this data, perform queries, and manipulate the data structure using object-oriented principles.
You will receive or create the following files:
Bus.php
– Contains theBus
class definition.Booking.php
– Contains theBooking
class definition.index.php
– Contains the dummy data and where all task implementations will be written.
Implement the solutions inside
index.php
. Comment your code clearly and ensure outputs are readable.
Loop through the list of all buses and print the following for each:
- Bus ID
- Bus Name
- Total number of seats
Loop through the bookings list and display:
- Booking ID
- Passenger Name
- Bus Name (not just Bus ID)
- Date of travel
Hint: You will need to match the bus ID in each booking to a corresponding bus to get the name.
Write code to filter and display all bookings made for 2025-05-01
only.
Display:
- Booking ID
- Passenger Name
- Bus Name
For each bus in the system, count and display how many times it has been booked.
Display:
- Bus Name
- Total number of bookings for that bus
Write a function called addBooking()
that accepts the following parameters:
bookingId
busId
passengerName
date
This function should:
- Create a new
Booking
object - Add it to the
$bookings
array - After adding, display all bookings again to confirm the update
Criteria | Details |
---|---|
✅ Code Organization | Use of OOP, proper use of classes and properties |
✅ Array Manipulation | Filtering, searching, and aggregating array data |
✅ Logic Clarity | Does the solution make logical sense and handle data correctly? |
✅ Reusability | Use of functions or utility methods when appropriate |
✅ Code Readability | Proper comments, indentation, and variable naming |
If time permits, consider writing an additional function that checks:
- Available seats on a bus for a specific date
- Output: Bus Name - Booked: X / Available: (Total - X)
Time: 30–45 minutes