In: Computer Science
Ruby programming
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 file Holiday.rb. Put
your main driver code in the file main.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.
july4 = Holiday.new( "Independence Day", 4, "July" ) if (xmas.sameDay?( thanksgiving )) if (thanksgiving.sameMonth?( xmas )) end |
here is July 4 information!! |