Question

In: Computer Science

Ruby programming I'd like you to create the class Holiday as described below. An object of...

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.

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!

Solutions

Expert Solution


Related Solutions

Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then...
Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then calculates the arithmetic mean (otherwise known as the average), the median (that is, the number that splits the set of value in half with half being above and half being below the number), and the standard deviation (that is, the average of distance each number is from the mean then squared). Further information about these calculations can be found here: average: http://en.wikipedia.org/wiki/Average (add up...
Here's what I'd like you to do. In your initial post, I'd like you to address...
Here's what I'd like you to do. In your initial post, I'd like you to address the historical understanding of a corporation's purposes and objectives. What has been the traditional approach to the objectives and purposes of corporations? Then, I'd like you to consider if, in our present age, those are the only objectives and purposes of corporations. As time has gone on, are there other objectives and purposes of corporations that society (and courts) now accept? If so, what...
You will work with MyInteger class (like an int, but it will be an object) by...
You will work with MyInteger class (like an int, but it will be an object) by obtaining the two files, MyInteger.h and testMyInteger.cpp. Create the file MyInteger.cpp by implementing the member and friend functions for the class. ==============MyInteger.h============== #ifndef MYINTEGER_H #define MYINTEGER_H #include <iostream> using namespace std; class MyInteger { public: MyInteger(int v = 0); void setValue(int v); int getValue() const; MyInteger operator+(const MyInteger &r) const; MyInteger operator-(const MyInteger &r) const; bool operator==(const MyInteger &r) const; friend ostream &operator<<(ostream &out,...
i'd like to get extra practice for a class. Create 5 multiple-choice questions covering 5 different...
i'd like to get extra practice for a class. Create 5 multiple-choice questions covering 5 different respiratory disorders. Pick 5 from the following list. Respiratory failure Asthma COPD Cystic Fibrosis Pneumonia TB Influenza. label the correct answer, & explain why
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaida
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
This week, you will create and implement an object-oriented programming design for your project. You will...
This week, you will create and implement an object-oriented programming design for your project. You will learn to identify and describe the classes, their attributes and operations, as well as the relations between the classes. Create class diagrams using Visual Studio. Review the How to: Add class diagrams to projects (Links to an external site.) page from Microsoft’s website; it will tell you how to install it. Submit a screen shot from Visual Studio with your explanation into a Word...
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
Create a class named GameCharacter to define an object as follows: The class should contain class...
Create a class named GameCharacter to define an object as follows: The class should contain class variables for charName (a string to store the character's name), charType (a string to store the character's type), charHealth (an int to store the character's health rating), and charScore (an int to store the character's current score). Provide a constructor with parameters for the name, type, health and score and include code to assign the received values to the four class variables. Provide a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT