0

我正在编写一个简单的音乐数据库和 ATM 我正在​​尝试创建一个播放列表类,它可以让用户将他们的音乐(先前输入数据库类的 4 首曲目)组织成 3 首歌曲的播放列表。

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

目前我收到这个;


进入播放列表工具...

您好,欢迎来到播放列表生成器!
请从下面的数据库中选择要添加到新播放列表的曲目(使用键 1-4)
插槽 1:树木:微风:2.34:128
1
错误:数据库中没有可用空间
插槽A:歌曲@3a1ec6
槽B:歌曲@1ba6076
槽 C : 歌曲@112e7f7
     菜单
0 退出
1个进口轨道
2 显示全部
3 建立一个播放列表(需要数据库中至少 1 首曲目)

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

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

    }


}

任何帮助都会非常感谢,

4

1 回答 1

0

System.out.println("Slot A : "+playlisttrackA); this calls the toString() method of Song (which is derived from Object). By default it prints the hash code of an object.

You should better print playlisttrackA.songname if I understand your code right.

于 2013-05-03T08:26:36.130 回答