0% found this document useful (0 votes)
10 views6 pages

Python Question

Python question
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Python Question

Python question
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Assignment 12

Classes and Object - Online Movie_ticket as Object


In this assignment the idea is to use a Movie_Ticket class to capture what you
need for recording and displaying the details of a MovieTicket from an online
store like TicketMaster or Fandango. This is a Class and Object assignment.
For the assignment you must define and implement the Movie_Ticket class so
that the code ( main ) shown immediately below can produce the result as
required. You will need to define the five private variables of the Movie_Ticket
class: the ticket_price, num_adults, num_seniors, num_kids and detail.
You have to have a an __init__ function ( constructor ), that takes four input
parameters for the num_adults, num_seniors, num_kids and detail, but not
ticket_price which should be set to a default value of 13.99 inside the init
function.
You will also need to create the remaining methods that are used in the code
below the accessors and mutators. The contents of the main function and the
output for the print are shown below. Copy, and do not change, the code below.
Pay close attention to the values in the output. If you do not match the details
correctly, some of your values will not be the same as those shown. (Hint: There’s
a reason that the get_invoice_price() method is not called get_ticket_price() )
Name this main file given below youOrderReceipt.py, e.g. AjoyOrderReceipt.py.
( This main is already given below. You just have to rename the file).
Part B:
Create a second main file youOrderReceiptList.py e.g. AjoyOrderReceiptList.
Using a list of movie_ticket objects, instead of movie_ticket1, movie_ticket2, etc.
Create movie_ticket1, movie_ticket2, movie_ticket3 and movie_ticket4 and
change the ticket_price using set_ticket_price as in the main below and then add
them in a list called movie_ticket_firstname_list. For each movie_ticket in the list
print the object and Use the list and the for loop to find the total_invoice_price
and total_attendees as in part A. Both mains should generate the same results.
Turn in your zipped package folder with all the three .py source
files(movie_ticket.py and the two main files). Having correct formatting will now
be part of the grade.
Here is the code for the first main. Copy and paste and rename the file to the
required name. But contents of the file should not be changed:
Here are the rules for calculating the total invoice price for one instance of a
movie ticket and calculating the total attendees.
Calculating the total invoice price:
 The regular price ticket for a movie is set to be $13.99
 Senior Adults get a 15% discount on the regular price ticket.
 Children get a 20% discount on the regular price ticket.
 For a new movie and a movie which is a hit, the regular price ticket can be
changed individually for a movie by the theater and we do that using the
mutator function set_ticket_price.
 get_invoice_price should include three line items.
o Need to calculate the price of the tickets for regular adults.
o Need to calculate the price of tickets for Senior citizens.
o Need to calculate the price of the tickets for children.
o And the invoice_price is the sum of these three charges in dollars.
Calculating the total attendees:
 The init function takes the attributes in this order:
o Total Number of Adults, then
o Total number of Senior Citizens,
o Total number of Children
 Please note that the total number of adults include total number of senior
citizens also and the first number passed in has to be greater than the
second number passed in. No validation required. Assume its always passed
in that way.
 So for example
o movie_ticket1 = movie_ticket.Movie_Ticket(5, 2, 3 "Red One, Nov
26th - 3:30 pm")
o Total Number of Adults including senior citizens = 5
o Total Number of Senior citizens = 2
o Total number of Children = 3
o Details of the movie being watched: “Red One” on November 26th at
3:30 pm.

#Header
#This program calculates the total Online revenue price
in dollars for the movie_tickets.
#And the total attendees who bought tickets Online.
#IPO

import movie_ticket

def main():
total_invoice_price = 0.0
total_attendees = 0
# Put the 4 movie_tickets being invoiceed in
movie_ticket1 through movie_ticket 4
movie_ticket1 = movie_ticket.Movie_Ticket(5, 2, 3,
"Red One, Nov 26th - 3:30 pm")
movie_ticket2 = movie_ticket.Movie_Ticket(7, 3, 0,
"Wicked, Nov 26th - 6:40 pm")
movie_ticket3 = movie_ticket.Movie_Ticket(3, 2, 1,
"Moana, Nov 26th - 2:00 pm")
movie_ticket4 = movie_ticket.Movie_Ticket(4, 2, 2,
"The Best Christmas Pageant Ever, Nov 26th - 9:55 pm")
movie_ticket2.set_ticket_price(18.79)
movie_ticket3.set_ticket_price(15.29)
#The code above is repeated in the second main
also.

# Show the details of the invoice using __str__()


print("Here are your shopping cart contents.")
print("-------------------------------------")
print(movie_ticket1)
print(movie_ticket2)
print(movie_ticket3)
print(movie_ticket4)

# Compute the invoice price and invoice weight in


this section
total_invoice_price +=
movie_ticket1.get_invoice_price()
total_invoice_price +=
movie_ticket2.get_invoice_price()
total_invoice_price +=
movie_ticket3.get_invoice_price()
total_invoice_price +=
movie_ticket4.get_invoice_price()
total_attendees += movie_ticket1.get_attendees()
total_attendees += movie_ticket2.get_attendees()
total_attendees += movie_ticket3.get_attendees()
total_attendees += movie_ticket4.get_attendees()
# Here we show the total Online revenue and
attendees
print(f"The total online revenue for movie tickets
is ${ total_invoice_price:.2f}")
print(f"The total attendees booked through online
is: {total_attendees:.0f}")
#End of main

if __name__ == "__main__":
main()

The method __str__() should print out as shown below


for each movie_ticket.

Here are your shopping cart contents.


-------------------------------------
Movie Ticket(s) have been ordered at a price of $13.99
for the movie "Red One" with show timing as follows:
Nov 26th - 3:30 pm.

Movie Ticket(s) have been ordered at a price of $18.79


for the movie "Wicked" with show timing as follows: Nov
26th - 6:40 pm.

Movie Ticket(s) have been ordered at a price of $15.29


for the movie "Moana" with show timing as follows: Nov
26th - 2:00 pm.
Movie Ticket(s) have been ordered at a price of $13.99
for the movie "The Best Christmas Pageant Ever" with
show timing as follows: Nov 26th - 9:55 pm.

You might also like