public class Holiday { //declaring variables private String name; private int day; private String month; //creating constructor that will Initialize variables public Holiday(String name, int day, String month) { this.name = name; this.day = day; this.month = month; } //sameMonth method

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question
Give the output of the following java program code. Screenshot (if applicable)
public class Holiday {
//declaring variables
private String name;
private int day;
private String month;
//creating constructor that will Initialize variables
public Holiday (String name, int day, String month) {
this.name = name;
this.day = day;
this.month = month;
}
//sameMonth method
public boolean sameMonth(Holiday h) {
//check if both month are equals
if((h.month).equalsIgnoreCase(this.month))
return true;
else
return false;
}
public double aveDate(Holiday [] holidays) {
//declaring variable to hold sum
double sum=0;
//iterate over array
for (Holiday h:holidays) {
//add days
sum=sum+h.day;
}
//find and return average
return sum/holidays.length;
}
public static void main(String[ args) {
//creating Holiday object with values
Holiday h=new Holiday("Independence Day", 4, "July");
}
}
Transcribed Image Text:public class Holiday { //declaring variables private String name; private int day; private String month; //creating constructor that will Initialize variables public Holiday (String name, int day, String month) { this.name = name; this.day = day; this.month = month; } //sameMonth method public boolean sameMonth(Holiday h) { //check if both month are equals if((h.month).equalsIgnoreCase(this.month)) return true; else return false; } public double aveDate(Holiday [] holidays) { //declaring variable to hold sum double sum=0; //iterate over array for (Holiday h:holidays) { //add days sum=sum+h.day; } //find and return average return sum/holidays.length; } public static void main(String[ args) { //creating Holiday object with values Holiday h=new Holiday("Independence Day", 4, "July"); } }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Print statement
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage