Created
November 1, 2021 15:56
-
-
Save SiddharthManthan/dbc1cc943e501e7ea7c2cc3a53108f6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SimpleDate { | |
private int day; | |
private int month; | |
private int year; | |
public SimpleDate(int day, int month, int year) { | |
this.day = day; | |
this.month = month; | |
this.year = year; | |
} | |
public int getDay() { | |
return this.day; | |
} | |
public int getMonth() { | |
return this.month; | |
} | |
public int getYear() { | |
return this.year; | |
} | |
public boolean equals(Object compared) { | |
// if the variables are located in the same position, they are equal | |
if (this == compared) { | |
return true; | |
} | |
// if the type of the compared object is not SimpleDate, the objects are not equal | |
if (!(compared instanceof SimpleDate)) { | |
return false; | |
} | |
// convert the Object type compared object | |
// into a SimpleDate type object called comparedSimpleDate | |
SimpleDate comparedSimpleDate = (SimpleDate) compared; | |
// if the values of the object variables are the same, the objects are equal | |
if (this.day == comparedSimpleDate.day && | |
this.month == comparedSimpleDate.month && | |
this.year == comparedSimpleDate.year) { | |
return true; | |
} | |
// otherwise the objects are not equal | |
return false; | |
} | |
@Override | |
public String toString() { | |
return this.day + "." + this.month + "." + this.year; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment