Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java: Holiday:An object of class Holiday represents a holiday during the year. This class has three instance variables: name, which is a String representing

In Java:

Holiday:An object of class Holiday represents a holiday during the year. This class has three instance variables:

name, which is a String representing the name of the holiday

day, which is an int representing the day of the month of the holiday

month, which is a String representing the month the holiday is in

public class Holiday {

private String name

private int day

private String month

// your code goes here

}

  1. Write a constructor for the class Holiday, which takes a String representing the name, an int representing the day, and a String representing the month as its arguments, and sets the class variables to these values.
  2. Write a static method inSameMonth, which compares two instances of the class Holiday, and returns the Boolean value true if they have the same month, and false if they do not. Show how it is used
  3. Write a static method avgDate which takes an array of base type Holiday as its argument, and returns a double that is the average of the day variables in the Holiday instances in the array. You may assume that the array is full (i.e. does not have any null entries). Show how it is used
  4. Write getters and setters to access the name, day, and month fields
  5. Write a method toString that returns the name of the holiday followed by the dat For example, if in the Holiday object name = Mayday, month = May, and day = 1, then toString should return Mayday: May 1
  6. Write a piece of code that creates a Holiday instance with the name Independence Day, with the day 4, and with the month July.

Here is the UML:

image text in transcribed

Once again, in standard UML parlance, + indicates that a field or method is public and - indicates that a field or method is private. An underlined field or method indicates it is static.

I have written the code to create a few holidays and put them in an array to get you started so you can test out the methods.

public class Holiday { private String name; private int day; private String month; public static void main(String[] args) { Holiday[] holidays = new Holiday[5]; holidays[0] = new Holiday("May Day", 1, "May"); } }

Holiday -name: String -day: int -month: String +Holiday(name: String, day:int, month: String) +inSameMonth(h1 Holiday, h2:Holiday): boolean +avgDate(holidays: Holidayl): double +getName(): String +setName(name: String) +getDay(): int +setDay(day: int) +getMonth(): String +setMonth(month: String) +toString(): String

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

1. Select the job or jobs to be analyzed.

Answered: 1 week ago