Java 播放列表类音乐数据库

Java 播放列表类音乐数据库,java,database,reference,playlist,Java,Database,Reference,Playlist,我正在编写一个简单的音乐数据库,我正在尝试创建一个播放列表类,该类允许用户将他们的音乐(之前输入数据库类的4首曲目)组织到一个包含3首歌曲的播放列表中 在用户选择要放入播放列表的歌曲后,该方法旨在搜索新播放列表中最近的空闲位置,并将歌曲变量(艺术家、名称、持续时间和文件大小)放入其中 此刻,我收到了这封信 正在进入播放列表工具 Hello, welcome to the playlist builder! Please select a track to add to the new play

我正在编写一个简单的音乐数据库,我正在尝试创建一个播放列表类,该类允许用户将他们的音乐(之前输入数据库类的4首曲目)组织到一个包含3首歌曲的播放列表中

在用户选择要放入播放列表的歌曲后,该方法旨在搜索新播放列表中最近的空闲位置,并将歌曲变量(艺术家、名称、持续时间和文件大小)放入其中

此刻,我收到了这封信


正在进入播放列表工具

Hello, welcome to the playlist builder! Please select a track to add to the new playlist from the database below(using keys 1-4) Slot 1:Trees:Breeze:2.34:128 1 Error: there is no free space in the database Slot A : Song@3a1ec6 Slot B : Song@1ba6076 Slot C : Song@112e7f7 MENU 0 EXIT 1 IMPORT TRACK 2 SHOW ALL 3 Build a playlist(requires atleast 1 track in database) 任何帮助都将非常感谢,

System.out.println(“插槽A:+playlittrackA”)
这将调用
Song
toString()
方法(该方法源自
对象
)。默认情况下,它打印对象的名称


如果我正确理解您的代码,您最好打印playlytracka.songname。

我必须更改为返回声明,谢谢。还有关于为什么我的播放列表已满的想法吗?您可以通过使用调试器轻松了解这一点;-)不知何故,所有的
歌曲文件大小都是
=0
。我看不到您在哪里设置歌曲(调用了
playlayobject
的位置在哪里?),并且可能会出现NullPointerException(未抛出),因此我不知道。
public class Playlist {

    Song songDataPlay = new Song();
    static UserInterface UI = new UserInterface();

    static Song playlisttrackA = new Song();
    static Song playlisttrackB = new Song();
    static Song playlisttrackC = new Song();

    private int MAX_TIME;
    private double totalSize;
    private double totalTIme;

    String playlistClassArtist, playlistClassName;
    double playlistClassDuration;
    int playlistClassFileSize;

    static String playlistArtist;
    static String playlistName;
    static double playlistDuration;
    static int playlistFileSize;
    static Song newplaySong;
    static Song newSong;

    static Song carryfromuserintoplaylist = UI.newPlaylistSongIN;

    public void playlistObject(Song a, Song b, Song c) {
        this.playlisttrackA = a;
        this.playlisttrackB = b;
        this.playlisttrackC = c;
    }


    public static void playlistAllocation() {
        newSong = UI.newPlaylistSongIN;
        Playlist plu = new Playlist();
        SongDatabase SD = new SongDatabase();
        Song newSong = carryfromuserintoplaylist;


        if (playlisttrackA.songfileSize == 0) {

            setSongA(newplaySong);

            System.out.println("Slot A : " + playlisttrackA);
            System.out.println("Slot B : " + playlisttrackB);
            System.out.println("Slot C : " + playlisttrackC);

            newplaySong = newSong;

        } else if (playlisttrackB.songfileSize == 0) {

            setSongB(newplaySong);

            System.out.println("Slot A : " + playlisttrackA);
            System.out.println("Slot B : " + playlisttrackB);
            System.out.println("Slot C : " + playlisttrackC);

            newplaySong = newSong;

        } else if (playlisttrackC.songfileSize == 0) {

            setSongC(newplaySong);

            System.out.println("Slot A : " + playlisttrackA);
            System.out.println("Slot B : " + playlisttrackB);
            System.out.println("Slot C : " + playlisttrackC);

            newplaySong = newSong;

        } else {

            System.out.println("Error: there is no free space in the database");

            System.out.println("Slot A : " + playlisttrackA);
            System.out.println("Slot B : " + playlisttrackB);
            System.out.println("Slot C : " + playlisttrackC);

        }
    }

    public static void setSongA(Song newSong) {

        playlisttrackA = newplaySong;

        playlisttrackA.songartist = newplaySong.songartist;
        playlisttrackA.songname = newplaySong.songname;
        playlisttrackA.songduration = newplaySong.songduration;
        playlisttrackA.songfileSize = newplaySong.songfileSize;

    }

    public Song getSongA() {

        return (playlisttrackA);
    }


    public static void setSongB(Song newSong) {

        playlisttrackB = newplaySong;

        playlisttrackB.songartist = newplaySong.songartist;
        playlisttrackB.songname = newplaySong.songname;
        playlisttrackB.songduration = newplaySong.songduration;
        playlisttrackB.songfileSize = newplaySong.songfileSize;

    }


    public Song getSongB() {

        return (playlisttrackB);
    }


    public static void setSongC(Song newSongC) {

        playlisttrackC = newplaySong;

        playlisttrackC.songartist = newplaySong.songartist;
        playlisttrackC.songname = newplaySong.songname;
        playlisttrackC.songduration = newplaySong.songduration;
        playlisttrackC.songfileSize = newplaySong.songfileSize;

    }

    public Song getSongC() {

        return (playlisttrackC);

    }

    public String returnPlaylist() {


        if (playlisttrackA.songfileSize == 0 && playlisttrackB.songfileSize == 0 && playlisttrackC.songfileSize == 0) {
            return ("Error ; No new playlists have been added.");
        } else if (playlisttrackB.songfileSize == 0 && playlisttrackC.songfileSize == 0) {
            return ("You have imported:" + newplaySong.songname + " By " + newplaySong.songartist + " to slot A in the new playlist");
        } else if (newplaySong.songfileSize == 0) {
            return ("You have imported:" + newplaySong.songname + " By " + newplaySong.songartist + "  to slot B in the new playlist");
        } else {
            return ("You have imported:" + newplaySong.songname + " By " + newplaySong.songartist + "  to slot C in the new playlist");
        }

    }


}