In the assignment, my professor asked us to create a class named Date2 and creat
ID: 3541260 • Letter: I
Question
In the assignment, my professor asked us to create a class named Date2 and create three global variables: month, day, year. All the variables are integers. So I created the proper constructors as requested and overwrote the copy method and toString. However, I do not understand the following part of the assigment:- An equals method returns true if the passed Date2 object matches the current Date2 object, field value for field value.
In the assignment, my professor asked us to create a class named Date2 and create three global variables: month, day, year. All the variables are integers. So I created the proper constructors as requested and overwrote the copy method and toString. However, I do not understand the following part of the assigment:
Explanation / Answer
class Date2
{
public int month;
public int day;
public int year;
public boolean equals(Date2 passed)
{
// you are looking for below code snippet;
// u should return true only when month is same as passed month, day is same as passed day and year same as passed year.
// add this function to your class to get it complete.
return (month==passed.month && day==passed.day && year==passed.year);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.