Answer:
See explaination
Explanation:
class Episode{
//Private variables
private String title;
private int seasonNumber;
private int episodeNumber;
//Argumented constructor
public Episode(String title, int seasonNumber, int episodeNumber) {
this.title = title;
this.seasonNumber = seasonNumber;
this.episodeNumber = episodeNumber;
}
//Getter and setters
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getSeasonNumber() {
return seasonNumber;
}
public void setSeasonNumber(int seasonNumber) {
this.seasonNumber = seasonNumber;
}
public int getEpisodeNumber() {
return episodeNumber;
}
public void setEpisodeNumber(int episodeNumber) {
this.episodeNumber = episodeNumber;
}
public boolean comesBefore(Episode e){
//Check if titles' match
if(this.title.equals(e.getTitle())){
//Compare season numbers
if(this.seasonNumber<e.seasonNumber){
return true;
}
//Check if season numbers match
else if(this.seasonNumber==e.getSeasonNumber()){
return this.episodeNumber<e.getEpisodeNumber();
}
}
return false;
}
atOverride // replace the at with at symbol
public String toString() {
return title+", season "+seasonNumber+", episode "+episodeNumber;
}
}
class Main{
public static void main(String[] args) {
Episode e = new Episode("Friends",1,1);
System.out.println(e);
Episode e2 = new Episode("The Wire",3,5);
System.out.println(e2);
System.out.println(e.getTitle()+" comes before "+e2.getTitle()+" = "+e.comesBefore(e2));
}
}