EDIT: IT WORKED THANKS TO EVERYONE!
For an assignment I have to construct a java class that checks whether or not the year of a specific date and time, exactly in the same form as this: "28/04/2019 18:06:25" , is a leapyear. I managed to write the code that checks the leapyear. However our assignment states that there should be an equals method (public boolean equals(Object other)) that checks whether the current instance is the same time as the given object. I really don't know how to do this, the best I could come up with is this:
public class DateTime {
private static String datumtijd;
public DateTime(String dateTime){
datumtijd = dateTime;
}
public void setDateTime(String newtime){
datumtijd = newtime;
}
public boolean equals(Object other){
return (datumtijd.equals(other.datumtijd));
}
public int getDay(){
char nulkarakter = datumtijd.charAt(0);
char nul = 0;
if (nulkarakter == nul){
String day = datumtijd.substring(1);
int dayint = Integer.parseInt(day);
return dayint;
}
else {
String daylang = datumtijd.substring(0, 2);
int daylangint = Integer.parseInt(daylang);
return daylangint;
}
}
...
But this doesn't seem to work. Sorry for being such a noob but I hope you could help me since I'm struggling with this for way to long.
Thank you so much!