Solved

Create a Movies Class that determines the cost of a ticket to a cinema.

Posted on 2010-11-09
3
960 Views
Last Modified: 2012-05-10
Are there any suggestions about the code I have created. I need to create a movies class that goes with Admission.php and Movies.html that I have created that determines the cost of a ticket based on the age. the full price of the ticket is 10.00. I need to assign the age to a private data member then use a public member function to determine the ticket price based on the following
under 5 = free
5-17 = half price
18-55 = full price
over 55 2.00 off full price
class Movies
	{

		private $age = 0; //declare private age
		private $ticketPrice = 10.00;//declare private ticket price 

                //create public function assign age       //it		
		public function Movies($age){
		$this->age = $age;
		}

		public function Movies($ticketPrice){
			
			if(age < 5){
			$this->ticketPrice = 0;
			}
			if(age > 5 && age < 18){
			$this->ticketPrice = $ticketPrice / 2;
			}
			if(age >= 18 && age <= 55){
			$this->ticketPrice = $ticketPrice;
			if(age > 55 ){
			$this->ticketPrice = $ticketPrice - 2.00;
			


	}

Open in new window

Admission.php
Movies.html
Movies.php
0
Comment
Question by:rcham68
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
Frosty555 earned 500 total points
ID: 34097203
In your movies class, remove the second constructor Movies() constructor. You don't want a constructor, you want a function which retrieves the correct age given the provided values.

            public function Movies($ticketPrice){

should be

            public function getDiscountTicketPrice($ticketPrice){

Then in your Admissions.php, you should instantiate the class, pass the age into the constructor when you instantiate it, and then call the "getDiscountTicketPrice()" function, passing in the ticket price of "10.00". The function should return the "new" ticket price according to the age, assuming you wrote that function correctly.

You can then use that value wherever you like in your Admissions.php page (show it on the page somewhere, store it in a database, process an order etc.).

A few other minor things in your other pages:

1) Don't require Movies.html in your Admissions.php page. It is not required. The Movies.html page posts data to the Admissions.php page, the two are not dependencies of each other.

2) Change the "method" property of your form from "GET" to "POST" in your Movies.html. Your form should be posting the data to the Admissions.php page.

3) In your Admission.php page, you should be doing some error checking - e.g. what happens if the user posts invalid data, or no data at all? It should maybe redirect back to the Movies.html page or show an error message.
0
 
LVL 31

Expert Comment

by:Frosty555
ID: 34097213
>>>you want a function which retrieves the correct age given the provided values

Sorry that should read "you want a function which retrieves the correct DISCOUNTED TICKET PRICE given the provided values"
0
 

Author Comment

by:rcham68
ID: 34098198
I have made the changes that you suggested but I am still not getting it to work. I think I have something wrong in the admission.php
<----Admission.php--->
<?php
require_once("Movies.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Movies</title>
</head>

<body>
<h1>Admissions</h1>

<?php



$ticketPrice = new Movies($age);
$ticketPrice->getTicketPrice();
$ticketPrice = 10.00;
$ticketPrice->getTicketPrice($ticketPrice);



echo"<p>The ticket price is $ticketPrice </p>\n";
?>




</body>

</html>

Open in new window

Movies.html
Movies.php
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now