Spotify播放列表迷你项目



以下是我的说明:焦点:创建一个可以包含1000首歌曲的类SpotifyPlaylist。Spotify播放列表应该包含一个由Song对象组成的数组
歌曲类:歌曲类将用于创建歌曲。每首歌都有标题、艺术家、专辑、长度、流派和播放次数。一定要包括任何必要的方法
SpotifyPlayist类:应该能够-添加歌曲-打印出所有歌曲-打印出给定相册中的所有歌曲-打印出给定流派的所有歌曲-打印给定艺术家的所有歌曲列表-打印出十首最受欢迎的歌曲。-播放歌曲(将播放次数加1,而不是实际播放音乐(-删除给定标题的歌曲。一定要包括任何可能有帮助的必要方法。例如,最好编写一个方法来检查播放列表中是否有歌曲。Tester:创建一个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;
}
}

对于您的实例变量,您可以添加任何类型的List来保存所有歌曲的列表(如果您发现自己需要它们,可以稍后创建更多(。

ArrayList是一个良好的开端。https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html如果你浏览一下文档,你可以看到你可以使用数组列表添加、删除、检查等。请记住,有些操作运行缓慢。在您的播放列表类中,您将在实例变量中仅保存此项

private ArrayList<Song> songs = new ArrayList<>();

然后初始化歌曲并将其添加到ArrayList中。

这个网站告诉你一些不同数据结构的运行时,你可能会觉得有帮助。例如,有些具有非常快速的插入或删除。https://www.bigocheatsheet.com/

创建一个包含您打算使用的所有方法的文档表可以帮助您准确地了解需要跟踪的内容。就我个人而言,我只会从ArrayList开始,然后在您完成主要部分后,尝试开发更高效的代码。

最新更新