Question: Need help with PHP code Create a Movie class that determines the cost of a ticket to a cinema, based on the moviegoer's age. Assume
Need help with PHP code
Create a Movie class that determines the cost of a ticket to a cinema, based on the moviegoer's age. Assume that the cost of a full-price ticket is $10. Assign the age to a private data member. Use a public member function to determine the ticket price, based on the following schedule:
| Age | Price |
|---|---|
| Under 5 | Free |
| 5 to 17 | Half Price |
| 18 to 55 | Full Price |
| Over 55 | $2 off |
This is what I have for code,
class movie
{
private $custage=0;
public $movieticprice=10.00
function construct()
{
$this->custage=custage;
}
function calprice($movieticprice)
{
switch($this->custage)
{
case($this->custage < 5): // The first condition that if age is less than 5
$this->movieticketPrice = 0;
break;
case ($this->custage > 5 && $this->custage < 18):// second case if age is between 5 and 17 including both
$this->movieticketPrice = $movieticketPrice / 2;
break;
case ($this->custage >= 18 && $this->custage <= 55): // Third case If age is between 18 and 55 including both
$this->movieticketPrice = $movieticketPrice;
break;
case ($this->custage > 55): //The forth case with age greater than 55
$this->movieticketPrice = $movieticketPrice - (float) ("2.00");
break;
}
return $this->movieticketPrice;
}
}
?>
This is the error I am getting,
Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting ',' or ';' in C:\wamp64\www\test2\Movie.php on line 11
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
