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

Using Ruby A dentist appointment schedule validation software Implement a superc

ID: 3589873 • 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

class Appointment
attr_accessor :info, :date, :year, :day, :month
def initialize(info, date)
@info = info
@date = Date.parse(date)
end

def get_info
@info
end
def get_date
@date
end

def get_year
@year = date.year
end

def get_month
@month = date.mon
end

end

class OneTime < Appointment

def OccursOn(year, month, day)
puts "The year you entered is #{year}"
puts "The month you entered is #{month}"
puts "The day you entered is #{day}"
appointments.each do |x|
puts "Month #{x.get_month}"
if x.get_month == month
puts x.get_date
puts x.get_info
end
end
end

end

class Day < Appointment

def OccursOn(day)
puts day
end

end

class Month < Appointment

def OccursOn(month)
puts month
end
end

appointments = []
appointment1 = Appointment.new("Root Canal", "31/10/2017")
appointment2 = Appointment.new("Cavity Filling", "31/12/2017")
appointments << appointment1 << appointment2
puts appointment1.get_date
puts appointment2.get_date
puts appointment1.get_info

onetime1 = OneTime.new("Root Canal", "31-10-2017")

puts "Enter a date to check (for example, 31-10-2017)"
checkdate = gets.chomp
checkdate = Date.parse(checkdate)

puts "Would you like to check against OneTime, Day or Month appointment?"
checkagainst = gets.chomp

if checkagainst == "OneTime" or checkagainst == "onetime"
onetime1.OccursOn(checkdate.year, checkdate.month, checkdate.day)
elsif checkagainst == "Day" or checkagainst == "day"
puts "Day" # run day check function
elsif checkagainst == "Month" or checkagainst == "Month"
puts "Month" # run month check function
else
puts "Invalid option."
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote