Ruby programming I'd like you to create the class Holiday as described below. An object of class
Question:
I'd like you to create the class Holiday as described below.
An object of class Holiday represents a holiday during a calendar year. This class has three private member variables:
- mName, a string, representing the name of the holiday
- mDay, an integer, representing the day of the month of the holiday
- mMonth, a string, representing the month the holiday is in
Create this class in the fileHoliday.rb. Put your main driver code in the filemain.rb. Connect the two files together by saying: require_relative 'Holiday'
- Write a constructor for the class which takes three arguments, a name, a day and a month value and sets the class variables to these arguments.
- Create a to_s( ) method that returns a string with the format: falls on
- Create the accessor methods name( ), day( ) and month( ) which return the values of the corresponding member variables.
- Create the method sameMonth?( Holiday ) which compares the passed argument to this Holiday and sees if they fall in the same Month.
- Create the method sameDay?( Holiday) which compares the passed argument to this Holidays and sees if they fall on the same day, regardless of the month.
Below is sample driver code which illustrates the kind of code I am looking for.
Client Code And Sample Output |
july4 = Holiday.new( \"Independence Day\", 4, \"July\" ) puts ( \"here is july4 information!!\" ) puts july4 thanksgiving = Holiday.new( \"Thanksgiving\", 25, \"November\" ) puts ( \"here is thanksgiving information!!\" ) day = thanksgiving.day( ) month = thanksgiving.month( ) name = thanksgiving.name( ) puts \"#{day} #{month} #{name}\" xmas = Holiday.new( \"Christmas Day\", 25, \"December\" ) day = xmas.day( ) month = xmas.month( ) name = xmas.name( ) puts \"#{day} #{month} #{name}\" if (xmas.sameDay?( thanksgiving )) puts \"thanksgiving and xmas fall on the same day!\" else puts \"thanksgiving and xmas do not fall on the same day!\" end if (thanksgiving.sameMonth?( xmas )) puts \"thanksgiving and xmas fall in the same month!\" else puts \"thanksgiving and xmas do not fall in the same month!\" end |
here is July 4 information!! Independence Day falls on July 4 here is thanksgiving information!! 25 November Thanksgiving here is xmas information!! 25 December Christmas Day thanksgiving and xmas fall on the same day! thanksgiving and xmas do not fall in the same month! |