播放列表类音乐数据库

时间:2013-05-03 08:23:21

标签: java database reference playlist

我正在写一个简单的音乐数据库和ATM我正在尝试创建一个播放列表,让用户将他们的音乐(之前输入数据库类的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)

我是否正确地猜测返回的是对变量位置的引用而不是变量本身?

Playlist.class的代码是;

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");
        }

    }


}

任何帮助都会非常感谢,

1 个答案:

答案 0 :(得分:0)

System.out.println("Slot A : "+playlisttrackA);这会调用toString()的{​​{1}}方法(来自Song)。默认情况下,它会打印对象的hash code

如果我理解你的代码,你应该更好地打印Object