Agradeço sugestões de melhoria e feedbacks.
Classe Main:
import models.Favorites;
import models.Music;
import models.Podcast;
public class Main {
public static void main(String[] args) {
Music musicA = new Music();
musicA.setTitle("Say yes");
musicA.setGenre("Rock Indie");
for (int i = 0; i < 834251; i++) {
musicA.play();
if (i % 2 == 0) {
musicA.like();
}
}
Podcast podcastB = new Podcast();
podcastB.setTitle("Podepah Podpah");
podcastB.setHost("Igão e Mítico");
for (int i = 0; i < 487587; i++) {
podcastB.play();
if (i % 2 == 1) {
podcastB.like();
}
}
Favorites favorites = new Favorites();
favorites.include(musicA);
favorites.include(podcastB);
}
}
Classe Audio:
package models;
public class Audio {
private String title;
private int reproductions;
private int likes;
private int rating;
private String about;
public void like() {
this.likes++;
}
public void play() {
this.reproductions++;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getReproductions() {
return reproductions;
}
public int getLikes() {
return likes;
}
public int getRating() {
return rating;
}
public String getAbout() {
return about;
}
public void setAbout(String about) {
this.about = about;
}
}
Classe Music:
package models;
public class Music extends Audio {
private String album;
private String artist;
private String genre;
public String getAlbum() {
return album;
}
public void setAlbum(String album) {
this.album = album;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
@Override
public int getRating() {
if (this.getReproductions() > 300000) {
return 5;
} else if (this.getReproductions() > 250000) {
return 4;
} else if (this.getReproductions() > 150000) {
return 3;
} else if (this.getReproductions() > 100000) {
return 2;
} else {
return 1;
}
}
}
Classe Podcast:
package models;
public class Podcast extends Audio {
private String host;
private String description;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public int getRating() {
if (this.getLikes() > 300000) {
return 5;
} else if (this.getLikes() > 250000) {
return 4;
} else if (this.getLikes() > 150000) {
return 3;
} else if (this.getLikes() > 100000) {
return 2;
} else return 1;
}
}
Classe Favorites:
package models;
public class Favorites {
public void include(Audio audio) {
if (audio.getRating() == 5) {
audio.setAbout("Fantástico, está entre os melhores!");
} else if (audio.getRating() == 4) {
audio.setAbout("Entre os populares do momento!");
} else if (audio.getRating() == 3) {
audio.setAbout("Muito comentado ultimamente!");
} else if (audio.getRating() == 2) {
audio.setAbout("Vale a pena conferir!");
} else if (audio.getRating() == 1) {
audio.setAbout("Salve para assistir mais tarde!");
} else {
audio.setAbout("...");
}
String resume = String.format("""
````````````````````````````````````
Título: %s
Curtidas: %d
Reproduções: %d
Classificação: %s
Sobre: %s
````````````````````````````````````
""", audio.getTitle(), audio.getLikes(), audio.getReproductions(), audio.getRating(), audio.getAbout());
System.out.println(resume);
}
}
Retorno: