【发布时间】:2021-06-18 20:51:33
【问题描述】:
这些是我的指示:
重点:创建一个可以包含多达 1000 首歌曲的类 Spotify 播放列表。 Spotify 播放列表应包含一个由 Song 对象组成的数组。
歌曲类:歌曲类将用于创建歌曲。每首歌都有标题、艺术家、专辑、长度、流派和播放次数。请务必包含任何必要的方法。
SpotifyPlayist 类:应该能够
- 添加歌曲
- 打印所有歌曲
- 打印出给定专辑中的所有歌曲
- 打印出给定类型的所有歌曲
- 打印给定艺术家的所有歌曲列表
- 打印出最受欢迎的 10 首歌曲。
- 播放歌曲(播放次数加 1,不是实际播放音乐)
- 删除给定标题的歌曲。
确保包含任何可能有帮助的必要方法。例如,最好编写一个检查歌曲是否在播放列表中的方法。测试器:创建一个 SpotifyPlaylist 对象并展示其所有功能。
我没有太多:我只有歌曲课。我有点卡在如何为我的播放列表类启动数组。任何事情都有帮助,TY!
public class Song
{
// Fields
private String title;
private String artist;
private String album;
private double lengthOfSong; // in seconds
private String genre;
private int numOfTimesPlayed;
// Constructors
/**
* Empty Constructor
*/
public Song() {
}
/**
* Overloaded Constructor for objects of class
*/
public Song(String title, String artist, String album, double lengthOfSong, String genre, int numOfTimesPlayed) {
this.title = title;
this.artist = artist;
this.album = album;
this.lengthOfSong = lengthOfSong;
this.genre = genre;
this.numOfTimesPlayed = numOfTimesPlayed;
}
// Getters
...
// Setters
...
// Methods
/**
* toString of the info of the class Song
*/
public String toString() {
String s = "Song: ";
s = s + "Title: " + getTitle() + " ";
s = s + "Artist: " + getArtist() + " ";
s = s + "Name of album: " + getAlbum() + " ";
s = s + "Length of song: " + getLengthOfSong() + " ";
s = s + "Genre of song: " + getGenre() + " ";
s = s + "Number of time played: " + getNumOfTimesPlayed() + " ";
return s;
}
/**
* A method that plays a song again
*/
public void playAgain() {
numOfTimesPlayed = numOfTimesPlayed + 1;
}
}
【问题讨论】:
标签: java