Question

Redesign Ticket class Add all "set" or "update" methods for each attribute in the Class (get...

Redesign Ticket class
Add all "set" or "update" methods for each attribute in the Class (get methods are there) Be sure that all update/get methods are included. Refer to your Shopping Cart program to help you here.

Rename any attributes, variables, methods, etc that help the Programmer using your code better understand what you are designing.

Create a __str__ method to print the contents of a specific ticket object
See p. 548 and Examples on p.530 & 546
------------------------------------------------------------------------------------------------------------------
Write the main part of the program:

Create several ticket objects (3 minimum) NOT a list this time (or at least for now)

Update at least two attributes from the main part of your program

Use the get method to print the changes that you made

Use the __str__ method to print the original ticket information for all ticket objects and again to print the objects after changes are made.

------------------------------------------------------------------------------------------------------------------

Remember to include several appropriate comments throughout your program. Your initial comment should include your name, date, class and section, name of your programming project, an explanation of what your program does AND your algorithm (each step of your program clearly listed). Print your results as a clear and informative statement. Your output should also include an explanation of what your program does for the user.

program python

class Ticket(object):

def __init__(self,name,start,dest,date,time,mode,price):

self.name = name

self.start = start

self.dest = dest

self.date = date

self.time = time

#modes = ["economy", "business", "first"]

self.mode = mode

self.price = price

def get_name(self):

return self.name

def get_start(self):

return self.start

def get_destination(self):

return self.dest

def get_date(self):

return self.date

def get_time(self):

return self.time

def get_mode(self):

return self.mode

def get_price(self):

return self.price

def print_ticket(self):

print(self.name)

print("Start: ", self.start, ", Destination: ", self.dest)

print("Date: ", self.date, ", Time: ", self.time)

print("Mode: ", self.mode, ", Price: ", self.price)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Ticket(object):

   def __init__(self,name,start,dest,date,time,mode,price):
       self.start = start
       self.name = name
       self.dest = dest
       self.date = date
       self.time = time
   #modes = ["economy", "business", "first"]
       self.mode = mode
       self.price = price

   def get_name(self):

   return self.name
  
   #setter
   def set_name(self,name):
   self.name = name

   def get_start(self):

   return self.start
  
   def set_start(self,start):   
   self.start = start

   def get_destination(self):
       return self.dest
      
   def set_destination(self,dest):   
       self.dest = dest
      
   def get_date(self):
       return self.date
      
   def set_date(self,date):   
       self.date = date

   def get_time(self):
       return self.time
      
   def set_time(self,time):   
       self.time = time

   def get_mode(self):
       return self.mode
   def set_mode(self,mode):
   self.mode=mode
      
   def get_price(self):
       return self.price
   def set_price(self,price):
   self.price=price
      
   def __str__(self):   
       return 'Ticket(name='+self.name+', start='+self.start+', dest='+self.dest+', date='+str(self.date)+', time='+str(self.time)+', mode='+str(self.mode)+', price='+str(self.price)+')'

   def print_ticket(self):
       print(self.name)

       print("Start: ", self.start, ", Destination: ", self.dest)

       print("Date: ", self.date, ", Time: ", self.time)
       print("Mode: ", self.mode, ", Price: ", self.price)
      
t1 = Ticket('Allan', 'Hyd','Kol','12-05-19','12:45','Air','230')
t2 = Ticket('Derek', 'NYC','WDC','12-05-19','11:45','Rail','50')
t3 = Ticket('Don', 'Hyd','Kol','12-05-19','10:45','Bus','100')
print(t1.__str__())
print(t2.__str__())
print(t3.__str__())
t1.set_price('300')
t1.set_destination('NDLS')
print('New Value price : '+t1.get_price())
print('New value Destination : '+t1.get_destination())
print(t1.__str__())
print(t2.__str__())
print(t3.__str__())

'''

Output:

Ticket(name=Allan, start=Hyd, dest=Kol, date=12-05-19, time=12:45, mode=Air, price=230)
Ticket(name=Derek, start=NYC, dest=WDC, date=12-05-19, time=11:45, mode=Rail, price=50)
Ticket(name=Don, start=Hyd, dest=Kol, date=12-05-19, time=10:45, mode=Bus, price=100)
New Value price : 300
New value Destination : NDLS
Ticket(name=Allan, start=Hyd, dest=NDLS, date=12-05-19, time=12:45, mode=Air, price=300)
Ticket(name=Derek, start=NYC, dest=WDC, date=12-05-19, time=11:45, mode=Rail, price=50)
Ticket(name=Don, start=Hyd, dest=Kol, date=12-05-19, time=10:45, mode=Bus, price=100)


'''

Add a comment
Know the answer?
Add Answer to:
Redesign Ticket class Add all "set" or "update" methods for each attribute in the Class (get...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT