Question

Help me with a python program : Implement a superclass appointment and subclasses Onetime, Daily and...

Help me with a python program :

Implement a superclass appointment and subclasses Onetime, Daily and Monthly. An appointment has a description(for example, "See the dentist") and a date. Write a method occursOn(year, month, day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a list of appointment objects with a mixture of appointments. Have the user enter a date and print out all appointments that occur on that date.

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

from datetime import date

class Appointment(object):
   def __init__(self,day,month,year,description):
       self.description=description
       self.date=date(year,month,day)
  
   def __unicode__(self):
       return self.description
      
   def occursOn(self,day,month,year):
       if self.date == date(year,month,day):
           return True
       else:
           return False
      
class Onetime(Appointment):
   def __init__(self,day,month,year,description):
       super(Onetime,self).__init__(day,month,year,description)
      
   def __unicode__(self):
       return self.description
      
      
class Daily(Appointment):
   def __init__(self,day,month,year,description):
       super(Daily,self).__init__(day,month,year,description)
      
   def __unicode__(self):
       return self.description
      
   #function over written  
   def occursOn(self,day,month,year):
       return True
       # because daily appointment is true for all days
      
      
class Monthly(Appointment):
   def __init__(self,day,month,year,description):
       super(Monthly,self).__init__(day,month,year,description)
      
   def __unicode__(self):
       return self.description
      
   #function over written  
   def occursOn(self,day,month,year):
       if self.date.day == day:
           return True
       else:
           return False

      
appList = []
appList.append(Daily(1, 1, 2013, "Do pushups"))
appList.append(Daily(15, 1, 2013, "Floss teeth"))
appList.append(Monthly(15, 12, 2012, "Backup data"))
appList.append(Onetime(21, 12, 2012, "Computer Science Final Exam"))
appList.append(Monthly(4, 2, 2013, "Call grandma"))
appList.append(Onetime(12, 4, 2013, "See dentist"))

day = int(input("Enter the day (0 to quit): "))
while day != 0 :
   month = int(input("Enter the month: "))
   year = int(input("Enter the year: "))
   for app in appList :
       if app.occursOn(day,month,year) :
           print(app.description)
   day = int(input("Enter the day (0 to quit): "))  

========================================================
See Output
Files saved Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.21 on linux share run D main.py main.py the day (0 to quit):

Thanks, PLEASE RATE if helpful

Add a comment
Know the answer?
Add Answer to:
Help me with a python program : Implement a superclass appointment and subclasses Onetime, Daily and...
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
  • (JAVA) In this assignment, you will implement a superclass Appointment and subclasses Onetime, Daily, and Monthly....

    (JAVA) In this assignment, you will implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a date. Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the mon.th matches. In your application part, fill an array of Appointment objects with a mixture of appointments. Have the...

  • *PYTHON* Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has the date,...

    *PYTHON* Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has the date, the month, the year, and the description of an appointment (e.g., “see the dentist”). Then, write a method occcursOn(year, month, day) that checks whether the appointment occurs on that date. In the test program, you should create a list of appointments using your subclasses of Onetime, Daily, and Monthly. Once you have those appointments available, allow the user to input day, month, and year...

  • Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has...

    Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has a description (for example "see the dentist") and a date. Write a method OccursOn (int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, check whether the day of the month matches. Ask the user to enter a date to check (for example, 2006 10 5), and ask to user if they want...

  • Write a Java program that implements a superclass Appointment and subclasses Onetime, Daily, and Monthly. An...

    Write a Java program that implements a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a date. It writes a method occursOn (int year, int month, int day) that checks whether the appointmentoccurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then it will fill an array of Appointment objects with a mixture of appointments. When the user...

  • 5.Implement a superclass Appointment and subclasses Onetime, Daily and Monthly. An appointment has a description (for...

    5.Implement a superclass Appointment and subclasses Onetime, Daily and Monthly. An appointment has a description (for example, “see the dentist”) and a date. Write a method occursOn(year,month,day) that checks whether the appointment occurs on that date. For example for a monthly appointment, you must check whether the day of the month matches and the appointment date started before the date entered. Then, fill a list of Appointment objects with a mixture of appointments. Have the user enter a date and...

  • Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

    Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...

  • Programming Assignment 6 Write a Java program that will implement a simple appointment book. The ...

    Programming Assignment 6 Write a Java program that will implement a simple appointment book. The program should have three classes: a Date class, an AppointmentBook class, and a Driver class. • You will use the Date class that is provided on Blackboard (provided in New Date Class example). • The AppointmentBook class should have the following: o A field for descriptions for the appointments (i.e. Doctor, Hair, etc.). This field should be an array of String objects. o A field...

  • I have this case study to solve. i want to ask which type of case study...

    I have this case study to solve. i want to ask which type of case study in this like problem, evaluation or decision? if its decision then what are the criterias and all? Stardust Petroleum Sendirian Berhad: how to inculcate the pro-active safety culture? Farzana Quoquab, Nomahaza Mahadi, Taram Satiraksa Wan Abdullah and Jihad Mohammad Coming together is a beginning; keeping together is progress; working together is success. - Henry Ford The beginning Stardust was established in 2013 as a...

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
ADVERTISEMENT