Java Reference
In-Depth Information
PROGRAMMING EXAMPLE: Movie Ticket Sale and Donation
to Charity
A movie in a local theater is in great demand. The theater owner has decided to
donate to a local charity a portion of the gross amount generated from the movie.
This example designs and implements a program that prompts the user to input the
movie name, adult ticket price, child ticket price, number of adult tickets sold,
number of child tickets sold, and percentage of the gross amount to be donated to
the charity. The output of the program is shown in Figure 3-14.
FIGURE 3-14 Output of theater sales program
Note that the decimal numbers are output with two decimal places.
Input: The input to the program consists of the movie name, adult ticket price, child
ticket price, number of adult tickets sold, number of child tickets sold, and
percentage of the gross amount to be donated to the charity.
Output: The output is as shown in Figure 3-14.
To calculate the amount donated to the local charity and the net sale, you first need
to determine the gross amount. To calculate the gross amount, you multiply the
number of adult tickets sold by the price of an adult ticket, multiply the number of
child tickets sold by the price of a child ticket, and then add these two numbers:
PROBLEM
ANALYSIS
AND
ALGORITHM
DESIGN
grossAmount = adultTicketPrice * noOfAdultTicketsSold
+ childTicketPrice * noOfChildTicketsSold;
Next, you determine the percentage of the amount donated to the charity, and then
calculate the net sale amount by subtracting the amount donated from the gross
amount. The formulas to calculate the amount donated and the net sale amount are
given below. This analysis leads to the following algorithm:
Search WWH ::




Custom Search