它不会显示专辑中的所有歌曲

时间:2019-03-19 19:06:36

标签: java

        package com.company;

        import java.util.ArrayList;

        public class JukeBox {
            public String Singer_Name;
            ArrayList<Album>Albums;

            public JukeBox(String singer_Name) {
                Singer_Name = singer_Name;
                this.Albums=new ArrayList<Album>();
            }

            public boolean CreatAlbum(String Album_Name){
                if(findAlbum(Album_Name)==null){
                    this.Albums.add(new Album(Album_Name));
                    return  true;
                }
                return false;
            }


            public boolean addSongs(String Album_Name,String Singer_Name,float Song_Duration,String released_Day){
                Album Alb = findAlbum(Album_Name);
                if(Alb!=null){
                    Alb.Creeat(Singer_Name,Song_Duration,released_Day);
                    return true;
                }
                return  false;
            }
            public void AlbumNames(){
                for(Album Alb:this.Albums){
                    System.out.println(Alb.getAlbum_Name());
                }
            }



            private Album findAlbum(String Album_Name){
                for(int i=0;i<this.Albums.size();i++){
                    Album Alb=this.Albums.get(i);
                    if(Alb.getAlbum_Name().equals(Album_Name))
                        return Alb;
                }
                return null;
            }





         public boolean AlbumSOngs(String Album_Name){
         Album Alb = findAlbum(Album_Name);

         if(Alb!=null){
             System.out.println("Songs in Album "+Alb.getAlbum_Name());
             ArrayList<Songs>SongList= Alb.getSongs();
             for(int i=0;i<SongList.size();i++){
                 System.out.println(SongList.get(i).Song_Name);
                 return true;
             }

         }
         return false;
         }

        }
    //Album Class

    package com.company;

    import java.util.ArrayList;

    public class Album {

        public String Album_Name;

        ArrayList<Songs>songs;

        public Album(String album_Name) {
            Album_Name = album_Name;
            this.songs=new ArrayList<Songs>();
        }

        public boolean Creeat(String Song_Name,float Song_duration,String releasedDay ){
            if(findSong(Song_Name)==null){
                this.songs.add(new Songs(Song_Name,Song_duration,releasedDay));
                return true;
            }
            return false;
        }

        private Songs findSong(String Song_Name){
            for (int i = 0; i < this.songs.size(); i++) {
                Songs song = this.songs.get(i);
                if (song.getSong_Name().equals(Song_Name)) {
                    return song;
                }
            }
            return null;
        }


        public String getAlbum_Name() {
            return Album_Name;
        }

        public ArrayList<Songs> getSongs() {
            return songs;
        }

    }
//Song Class
package com.company;

public class Songs {
    public String Song_Name;
    public float Song_duration;
    public String Song_releasedDay;

    public Songs(String song_Name, float song_duration, String song_releasedDay) {
        Song_Name = song_Name;
        Song_duration = song_duration;
        Song_releasedDay = song_releasedDay;
    }

    public String getSong_Name() {
        return Song_Name;
    }

}

我不确定为什么它不显示专辑中的所有歌曲名称,但是当我尝试显示所有专辑名称时,它会完美显示,但是每当我尝试在任何专辑中打印歌曲时,它只会显示第一首歌曲在专辑中添加名称,并忽略重置,点唱机类将数组中的专辑列为列表专辑类中的歌曲在数组中列表中...

0 个答案:

没有答案