Ruby programming
I'd like you to create the class Holiday as described below.
An object of class Holiday represents a holiday during acalendar 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 theholiday
- mMonth, a string, representing the month the holiday is in
Create this class in the file Holiday.rb. Putyour main driver code in the file main.rb. Connectthe 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 tothese arguments.
- Create a to_s( ) method that returns a string with theformat:
<> falls on < <>
- Create the accessor methods name( ), day( ) and month( ) whichreturn the values of the corresponding member variables.
- Create the method sameMonth?( Holiday ) which compares thepassed argument to this Holiday and sees if they fall in the sameMonth.
- Create the method sameDay?( Holiday) which compares the passedargument 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 Iam looking for.
Client Code And Sample Outputjuly4 = 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! |