Using Ruby A dentist appointment schedule validation software Implement a superc
ID: 3586845 • Letter: U
Question
Using Ruby
A dentist appointment schedule validation software
Implement a superclass Appointment and sub classes OneTime, Day and Month. An appointment has a description (for example, "Root Canal"), and dates information (you can use Date object or int Year, Int Month, Int Day). Fill an array of Appointment objects with a mixture of appointments.
Write a method OccursOn inside each of the sub classes that checks whether the appointment occurs on that date (OneTime), day (Day) or month (Month). Ask the user to enter a date to check (for example, 2006 10 5), and ask to user if they want to check against OneTime, Day or Month appointment. Based on what the user selected, OccursOn inside each of the sub class should run and display any matching appointment and associated descriptions.
Hint: For OneTime subclass, OccursOn need three inputs (Year, Month and Day) to validate, for Day subclass, OccursOn needs one input (Day) to validate, and for Month subclass, OccursOn need one input (Month) to validate. OccursOn is different for different subclasses.
Please provide your code and screenshot of how your code ran.
Explanation / Answer
appointment.rb
class Appointment
attr_accessor :description, :day, :month, :year
attr_reader :appType
def occursOn(day, month, year)
raise 'Not implemented'
end
#
# Class members
#
@@subclass_registar = {}
def self.registerClass(clazz)
@@subclass_registar[clazz] = self
end
def self.getInstance(clazz)
clazz = @@subclass_registar[clazz]
if clazz
clazz.new
else
raise "Error: No such type"
end
end
end
class OneTime < Appointment
def occursOn(day, month, year)
if @day == day && @month == month && @year == year
return true
end
false
end
# register subtype
registerClass(:OneTime)
end
class Day < Appointment
def occursOn(day, month, year)
if @day == day
return true
end
false
end
# register subtype
registerClass(:Day)
end
class Month < Appointment
def occursOn(day, month, year)
if @month == month
return true
end
false
end
# register subtype
registerClass(:Month)
end
=================================================================================
inquiry.rb
==========================================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.