После того, как человек поместил все желаемые статьи на лоток, они go помещаются в конец очереди у кассы. Чтобы смоделировать это, мы собираемся создать объект tillQueue, который затем будет связан с кассовым аппаратом. Подумайте о соответствующем коде для метода firstPersonInQueue (Совет: посмотрите на функцию array_shift)
Как реализовать это с помощью функции сдвига массива:
<?php
class tillQueue
{
// tillQueue is a list of persons
private $tillQueue;
/**
* Constructor
*/
function constructor()
{
$tillQueue = array();
}
/**
*Person joins the back of the queue
* @param person
*/
public function joinsBackOfQueue($person)
{
$this->tillQueue[] = $person;
}
/**
*If there is a queue, remove the first Person from
*the queue and return.
*If there is no one in the queue, this returns null.
* @return First person in queue or null
*/
public function firstPersonInQueue()
{
// method body omitted
}
/**
*Method checks whether there are persons in the queue.
* @return Whether or not a queue exists
*/
public function thereIsAQueue()
{
return sizeof($this->tillQueue) > 0;
}
}
?>