Question

In: Computer Science

You will write a PHP program to calculate the payment receipt for renting a number of...

You will write a PHP program to calculate the payment receipt for renting a number of movies, using a conditional structure.

Suppose that the rental rate depends on the number of movies rented by a customer at a time. There is a limit of renting a maximum of 20 movies at a time.

Conditions: For the first 2 movies rented, the rate is $5.50/movie. For the next 2 movies rented, the rate is $4.25/movie. For the next 3 movies rented, the rate is $3.00/movie. For any more movies rented (no more than 20), the rate is $2.00/movie.

Hence, if a customer rents 5 movies, two of those will be rented at $5.50, two for $4.25 and one for $3.00, for a total of (2*$5.50) + (2*$4.25) + $3.00 = $22.50.

1) Create a form that asks the customer for his/her name and the number of movies he/she would like to rent. On submit, display the total amount due (shown to 2 decimal places) on the same page. (15 points) 2) Save the customer’s submitted name in a flat file called “visitor.txt”. You should overwrite this name every time someone submits a name to the form. (10 points)

Give appropriate error or warning messages for both 1) and 2).

Solutions

Expert Solution

Screenshot of the Code:

Sample Output:

Output File:

Code to Copy:

<html>

<title>

Movie Rental

</title>

<head>

</head>

<body>

<h2 align="center">Movie Rental Form</h2>

<form action="" method="post">

<table align="center" border="4px">

<tr>

<td>Name: </td>

<td><input type="text" name="userName"/>

</tr>

<tr>

<td>Number of Movies to be Rented: </td>

<td><input type="text" name="numMoive"/>

</tr>

<tr colspan=>

<td colspan="4" align="center">

<input type="submit" value="Submit" name="submit"/>

</td>

</tr>

</table>

<p id = "demo"></p>

</form>

<?php

//On submit click

//get the name and number of movies.

if(isset($_POST['submit']))

{

$userName=$_POST['userName'];

$numberMoives=$_POST['numMoive'];

//Define the variable.

$cost=0;

//Calculate the cost as per the number of movies.

if($numberMoives<=20)

{

if($numberMoives<=2)

$cost+=$numberMoives*5.50;

else if($numberMoives<=4)

{

$cost=11.00;

$cost+=($numberMoives-2)*4.25;

}

else if($numberMoives<=7)

{

$cost=19.50;

$cost+=($numberMoives-4)*3.00;

}

else

{

$cost=28.50;

$cost+=($numberMoives-7)*2.00;

}

//Display the results.

echo "<h2 align='center'>".$userName." your total amount due: $".number_format($cost, 2)."</h2>";

//Create a file.

//Display the error message if the program is unable to create the file.

$visitorFile = fopen("visitor.txt", "w") or die("Unable to create the file!");

//Write the content in the file.

fwrite($visitorFile, $userName);

//Close the file.

fclose($visitorFile);

}

else

{

//Display the message for invalid input.

$msg = "you cannot rent more than 20 movies.";

echo "<script type='text/javascript'>alert('$msg');</script>";

}

}

?>

</body>

</html>


Related Solutions

In this assignment you will write a PHP program that reads from a data file, creates...
In this assignment you will write a PHP program that reads from a data file, creates an associative array, sorts the data by key and displays the information in an HTML table. Create a PHP file called hw4.php that will do the following: - Display your name. - Read text data from a file. The data file is hw3.txt. The file hw3.txt will hold the following text: PQRParrot, Quagga, Raccoon DEFDo statements, Else statements, For statements GHIGeese, Hippos, If statements...
Write a PHP Program to display all the $_SERVER elements
Write a PHP Program to display all the $_SERVER elements
Write an assembly program for the MSP430 to calculate the number of zeros and ones in...
Write an assembly program for the MSP430 to calculate the number of zeros and ones in an array. If the number of zeros is more than the number of ones, the red LED(connected to P1.0 on the MSP430 launchpad) will turn on. Otherwise, the green LED (connected to P1.6 on the MSP430 launchpad) will turn on.
(Write a program in C++) A local instructor wants you to write a program to calculate...
(Write a program in C++) A local instructor wants you to write a program to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60...
write a program called GradeCalculator that will calculate the grading statistics of a desired number of...
write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will also check for negative scores. If any...
Using Python write an application that will calculate a loan payment. To complete this, you are...
Using Python write an application that will calculate a loan payment. To complete this, you are required to write 2 functions, LoanPayment and InterestOnlyLoanPayment, as well as a test application that calls each of the functions to get the payment amount based on parameters supplied to the functions. The test application should output both the loan payment and the interest-only loan payment based on input values from the user. The LoanPayment function is defined as follows: Payment = Loan amount...
Write a MIPS Assembly program function to calculate the factorial of an input number. Analyze the...
Write a MIPS Assembly program function to calculate the factorial of an input number. Analyze the program for the value 10 and compute the Execution time in a MIPS processor at 2.4GHz. The CPI is 1.
Write a php program that writes numbers to a file. The file type should be .txt...
Write a php program that writes numbers to a file. The file type should be .txt and the file name should be numbers.tx. The numbers.txt should contain 10 random integers between 1 to 100 after the file is written.
Write a PHP program using HTML form. It will take Length, Width and Height of a...
Write a PHP program using HTML form. It will take Length, Width and Height of a box as input. When a button is pressed, it will calculate the Volume. If Volume is less than 25 then display the message “Small box”. If Volume is from 25 to 50, it will display the message “Medium box”. When the Volume is greater than 50, then display the message “Large box”.
Create a program that: Creates a sales receipt, displays the receipt entries and totals, and saves...
Create a program that: Creates a sales receipt, displays the receipt entries and totals, and saves the receipt entries to a file Prompt the user to enter the Item Name Item Quantity Item Price Display the item name, the quantity, and item price, and the extended price (Item Quantity multiplied by Item Price) after the entry is made Save the item name, quantity, item price, and extended price to a file When you create the file, prompt the user for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT