Last active
February 7, 2021 08:24
-
-
Save weihungchin/a4b1fa24ca1ac52ef382f3d831533c14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Song { | |
private String genre; | |
private String artist; | |
public Song(String genre, String artist) { | |
this.genre = genre; | |
this.artist = artist; | |
} | |
// Getter setter | |
public String getGenre() { | |
return genre; | |
} | |
public void setGenre(String genre) { | |
this.genre = genre; | |
} | |
public String getArtist() { | |
return artist; | |
} | |
public void setArtist(String artist) { | |
this.artist = artist; | |
} | |
// hashcode/equals | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
Song that = (Song) o; | |
if (genre != that.genre) | |
return false; | |
return artist != null ? | |
artist.equals(that.artist) : | |
that.artist == null; | |
} | |
@Override | |
public int hashCode() { | |
int result = genre != null ? genre.hashCode() : 0; | |
result = 31 * result + (artist != null ? | |
artist.hashCode() : 0); | |
return result; | |
} | |
// toString | |
@Override | |
public String toString() { | |
return "Song{" + | |
"genre='" + genre + '\'' + | |
", artist='" + artist + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment