Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

By using Python, . Implement a superclass Appointment and subclasses Onetime, Da

ID: 3766625 • Letter: B

Question

By using Python, . 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. • Fill a list of Appointment objects with a mixture of appointments (be creative). Have the user enter a date and print out all appointments that occur on that date. 1 • Give the user the option to add new appointments. The user must specify the type of the appointment, the description, and the date. • Give the user the option to save the appointment data to a file and reload the data from a file. The saving part is straightforward: Make a method save. Save the type, description, and date to a file. The loading part is not so easy. First determine the type of the appointment to be loaded, create an object of that type, and then call a load method to load the data.

Explanation / Answer

working python code compiled on ideone.

# your code goes here
from datetime import datetime


class Appointment():
def __init__(self, description, date):
self._description = description
self._date = date

def enter_datetime(self, date):
return datetime.strptime(date, "%Y-%m-%d").date()

def enter_description(self):
return self._description

def enter_date(self):
return self._date

def occurs_on(self, year, month, day):
date = "{}-{}-{}".format(year, month, day)
return self.enter_datetime(self._date) == self.enter_datetime(date)


class AppointmentBook():
def __init__(self):
self._appointments = []

def add_appointment(self, appointment_object):
self._appointments.append(appointment_object)

def remove_appointment(self, appointment_id):
self._appointments.pop(appointment_id-1)

def get_number_of_appointments(self):
return len(self._appointments)

def list_appointments(self):
output = []
for i, appointment in enumerate(self._appointments):
output.append("[{}] {} - {}".format(i+1, appointment.enter_date(), appointment.enter_description()))
return " ".join(output)

I have created the appointment class as specified in the problem. The function is created occursOn as per the given syntax.