No se trata de lo que quieres comprar, sino de quién quieres ser. Aprovecha el precio especial.

Antes: $249

Currency
$209

Paga en 4 cuotas sin intereses

Paga en 4 cuotas sin intereses
Suscríbete

Termina en:

14 Días
20 Hrs
1 Min
44 Seg
Curso Avanzado de Java SE

Curso Avanzado de Java SE

Anahí Salgado Díaz de la Vega

Anahí Salgado Díaz de la Vega

Ejercicio. Clases Anidadas

12/40

Lectura

Spotify tiene una relación Album - Song en donde Song será una clase que solo es utilizada en Album pues la definición de este es una colección de Song’s.

...

Regístrate o inicia sesión para leer el resto del contenido.

Aportes 123

Preguntas 2

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

Acá dejo mi versión de la implementación de la clase:
Album

public class Album {

    private String name;
    private String author;
    private int year;
    private Song[] songs;

    public Album(String name, String author, int year) {
        this.name = name;
        this.author = author;
        this.year = year;
    }

    public void setAlbum(String[] names, int[] durations) {
        Song[] songs = new Song[names.length];
        for (int i = 0; i < names.length; i++) {
            songs[i] = new Song(names[i], durations[i]);
        }
        this.songs = songs;
    }

    private String getAlbum() {
        StringBuilder sb = new StringBuilder();
        for (Song song : songs) {
            sb.append(song);
        }
        return sb.toString();
    }

    public String toString() {
        return "\nALBUM: " + name +
                "\nAUTHOR: " + author +
                "\nYEAR: " + year +
                "\n\n::SONGS::\n" + getAlbum();
    }


    private static class Song {

        private String name;
        private int duration;

        private Song(String name, int duration) {
            this.name = name;
            this.duration = duration;
        }

        public String toString() {
            return "\nName: " + name +
                    "\nDuration: " + duration + " seconds\n";
        }
    }
}

Main

    public static void main(String[] args) {
        String[] names = {"Uno", "Divenire", "Monday", "Andare", "Rose", "Primavera", "Oltremare", "L'origine Nascosta", "Fly", "Ascolta", "Ritornare", "Svanire"};
        int[] durations = {228, 402, 355, 422, 256, 444, 660, 192, 279, 289, 532, 449};
        Album album = new Album("Divenire","Ludovico Einaudi",2006);
        album.setAlbum(names, durations);
        System.out.println(album);
    }
public class Album{
		
		private class Song{
			private String nombre;
			private String artista;
		}
		private ArrayList<Song> canciones;
		private String nombreAlbum;
		
		public Album() {
		}
		public Album(ArrayList<Song> canciones, String nAlbum) {
			this.canciones = canciones;
			this.nombreAlbum = nAlbum;
		}
	}
public class Album {
	public class Song {
	}
}

Album album = new Album();
Album.Song song = album.new Song();

Esto no tiene mucha lógica para mi, porque yo puedo implementar la clase Autor que solo se va a utilizar en Song y no necesariamente tiene que estar anidada. La verdad sigo sin verle la utilidad a esta propiedad del lenguaje

public class Album {
	public static void main(String[] args) {
		
		Song song1 = new Song("SnarkyPuppy", "What About Me", "JazzFusion");
		Song song2 = new Song("DirtyLoops", "HitMe", "Pop Progressive");
		Song song3 = new Song("Jesus Molina", "Night in Tunisia", "Jazz");
		Song song4 = new Song("FourPLay", "Flying East", "Jazz Soul");
		Song song5 = new Song("Anthony Brancati", "Neo Funk", "Funk Soul");
		
		Set<Song> CollectionSongs = new HashSet<Song>();
		
		
		CollectionSong.add(song1);
		CollectionSong.add(song2);
		CollectionSong.add(song3);
		CollectionSong.add(song4);
		CollectionSong.add(song5);

		
	for (Song song : CollectionSongs) {
		System.out.println(song.getArtist() + song.getNameSong() + song.getGenre());
	}

	}
	
	public class Song{
		
	private String	artist;
	private String	nameSong;
	private String 	genre;
		
	public Song(String artist, String nameSong, String genre){
		this.artist = artist;
		this.nameSong = nameSong;
		this.genre = genre;
	
	}

	public String getArtist() {
		return artist;
	}

	public void setArtist(String artist) {
		this.artist = artist;
	}

	public String getNameSong() {
		return nameSong;
	}

	public void setNameSong(String nameSong) {
		this.nameSong = nameSong;
	}

	public String getGenre() {
		return genre;
	}

	public void setGenre(String genre) {
		this.genre = genre;
	}
	
	
	}
	}


primero, la interface para el atributo audio de la clase song

public interface IPlayable {
	public void play();
}

la clase álbum y dentro la clase song.
Dado que en spotify podemos buscar el álbum que queramos o buscar directamente la canción decidí hacer la clase Song no estática, ya que para encontrar una canción de un álbum debe existir dicho álbum.

public class Album {
	//the number of the song and the song
	public  HashMap <Integer,Song> songs;
	String artist;
	String name;
	short year;
	String recordsCompany;
	
	//constructor
	public Album(String artist, String name, short year, String recordsCompany) {
		super();
		this.artist = artist;
		this.name = name;
		this.year = year;
		this.recordsCompany = recordsCompany;
		songs = new HashMap <Integer,Song>();
		//this is for stablish the number of song in the album
		Scanner scanner = new Scanner(System.in);
		System.out.println("Number of songs for " + this.name);
		int numberOfSongs = scanner.nextInt();
		addSong(songs, numberOfSongs);
		
	}
	//Method to add songs to the list
	private void addSong(HashMap listSongs, int numberOfSongs) {
		
		for (int i = 0; i < numberOfSongs; i++) {
			this.songs.put(i + 1, new Song());
		}
		
	}
	
	//getters
	public String getArtist() {
		return artist;
	}

	public String getName() {
		return name;
	}

	public short getYear() {
		return year;
	}

	public String getRecordsCompany() {
		return recordsCompany;
	}
	//*********************Song inner class******************************
	public class Song {
		String name;
		String artist;
		short year;
		//atribute with an anonymous class
		IPlayable audio = new IPlayable() {
			@Override
			public void play() {
				System.out.println("lalalalalalalalalalalalalalalalalalalala");
			}
		};
		//construcutor
		public Song() {
			super();
			Scanner scanner = new Scanner(System.in);
			System.out.println("Name of the song: ");
			this.name = scanner.nextLine();
			System.out.println("Artist: ");
			this.artist = scanner.nextLine();
			System.out.println("Year of the song: ");
			this.year = scanner.nextShort();
		}
		//getters
		public String getName() {
			return name;
		}
		public String getArtist() {
			return artist;
		}
		public short getYear() {
			return year;
		}
	}

}
<code>
import java.util.ArrayList;
/**
 *
 * @author Hernandez
 */
public class Album {
    private int id;
    private ArrayList<Song> songs = new ArrayList();

    public int getId() {
        return id;
    }
  
    public ArrayList<Song> getSongs() {
        return songs;
    }

    public void setSongs(ArrayList<Song> songs) {
        this.songs = songs;
    }
    
    public class Song{
        private int id;
        private Album album;
        private double duration;

        public int getId() {
            return id;
        }

        public Album getAlbum() {
            return album;
        }

        public void setAlbum(Album album) {
            this.album = album;
        }

        public double getDuration() {
            return duration;
        }

        public void setDuration(double duration) {
            this.duration = duration;
        }
    }
}

//podria estar mejor, pero algo asi es mi idea

public class Album {

private ArrayList<Song> alSong;

public static class Song{

    private String album;
    private String nombre;
    private double duracion;

    public String getAlbum() {
        return album;
    }

    public void setAlbum(String album) {
        this.album = album;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public double getDuracion() {
        return duracion;
    }

    public void setDuracion(double duracion) {
        this.duracion = duracion;
    }
}

public ArrayList<Song> getAlSong() {
    return alSong;
}

public void setAlSong(ArrayList<Song> alSong) {
    this.alSong = alSong;
}


public void listar(){
    for (Song element:
         getAlSong()) {
        System.out.println(element.getAlbum());
        System.out.println(element.getNombre());
        System.out.println(element.getDuracion());
    }
}

}
public class Main {

public static void main(String[] args) {


    Album.Song alAlbunSong = new Album.Song();
    alAlbunSong.setAlbum("NOMBRE DEL ALBUM");
    alAlbunSong.setNombre("NOMBRE DE LA CANCIÓN");
    alAlbunSong.setDuracion(3.25);

    ArrayList<Album.Song> alAS = new ArrayList<Album.Song>();
    alAS.add(alAlbunSong);

    Album listaAlbum = new Album();
    listaAlbum.setAlSong(alAS);

    listaAlbum.listar();


}

}

import java.util.Date;
import java.util.List;

public class Album {

private int codigo;
private String Nombre;
private  List<Song> objSongs;

public int getCodigo() {
    return codigo;
}

public void setCodigo(int codigo) {
    this.codigo = codigo;
}

public String getNombre() {
    return Nombre;
}

public void setNombre(String nombre) {
    Nombre = nombre;
}

public List<Song> getObjSongs() {
    return objSongs;
}

public void setObjSongs(List<Song> objSongs) {
    this.objSongs = objSongs;
}

public class Song{

    private int codigo;
    private String artista;
    private String duracion;
    private String genero;
    private Date  publicacion;

    public Song()
    {

    }

    public int getCodigo() {
        return codigo;
    }

    public void setCodigo(int codigo) {
        this.codigo = codigo;
    }

    public String getArtista() {
        return artista;
    }

    public void setArtista(String artista) {
        this.artista = artista;
    }

    public String getDuracion() {
        return duracion;
    }

    public void setDuracion(String duracion) {
        this.duracion = duracion;
    }

    public String getGenero() {
        return genero;
    }

    public void setGenero(String genero) {
        this.genero = genero;
    }

    public Date getPublicacion() {
        return publicacion;
    }

    public void setPublicacion(Date publicacion) {
        this.publicacion = publicacion;
    }



}

}

Clase Album

package logica;

import java.util.ArrayList;

public class Album {
	
	private int id;
	private ArrayList<Song> songs;
	
	public Album(int id) {
		this.id = id;
	}
		
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}



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

	public void setSongs(ArrayList<Song> songs) {
		this.songs = songs;
	}
	
	public static ArrayList<Album> makeAlbum(){
		ArrayList<Album>albums = new ArrayList<Album>();
		for(int i=1; i<=5; i++) {
			Album album = new Album(i);
			album.setSongs(Song.makeSong(album));
			albums.add(album);
			
		}
		return albums;
	}


	public static class Song {
		
		private int id;
		private Album album;
		
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public Album getAlbum() {
			return album;
		}
		public void setAlbum(Album album) {
			this.album = album;
		}
		
		public Song(int id, Album album) {
			this.id = id;
			this.setAlbum(album);
		}
		
		//creando songs 
		public static ArrayList <Song> makeSong(Album album){
			ArrayList<Song> songs = new ArrayList<Song>();
			for(int i =1; i<= 5; i++) {
				songs.add(new Song( i, album));
			}			
			return songs;
			
		}
		
	}

}

Clase Main

import java.util.ArrayList;

import logica.Album.Song;

public class Main {

	public static void main(String[] args) {
			
		ArrayList<Album> albums = Album.makeAlbum();
		ArrayList<Album.Song> songs;
				
		System.out.println("Album");
		for (Album album : albums) {
			System.out.println("album " + album.getId());
			//informacion song 
			songs = album.getSongs();
			for (Song song : songs) {
				System.out.println(song.getId());
			}			
		}
				
	}
}
```java public class Album { public class Song { } } Album album = new Album(); Album.Song song = album.new Song(); ```
```js import java.util.ArrayList; public class Album { public static class Song { String nombre; int año; String genero; public Song(String nombre, int año, String genero) { this.año = año; this.genero = genero; this.nombre = nombre; } public int getAño() { return año; } public void setAño(int año) { this.año = año; } public String getGenero() { return genero; } public void setGenero(String genero) { this.genero = genero; } public String getNombre() { return nombre; } public void setNombre(String nombre) { this.nombre = nombre; } } } class Play { public static void main(String[] args) { Album.Song album = new Album.Song("Tnt", 1975, "rock"); Album.Song album1 = new Album.Song("bohemian rhapsody", 1975 , "rock"); Album.Song album2 = new Album.Song("back is black", 1980, "rock"); ArrayList<Album.Song> songArrayList= new ArrayList<>(); songArrayList.add(album); songArrayList.add(album1); songArrayList.add(album2); for (Album.Song song : songArrayList){ System.out.println("Nombre: " + song.getNombre() + "\n"+"Año: "+song.getAño()+"\n"+"Genero: "+song.getGenero()); } } } ```
`public class ``Album`` {` ` ` `String name;` ` ` `String band;` ` ``public class ``Song`` {` ` `` ``int duracion; ` ` `` `` ``String name;` `public Song(int dur, String name){` `this.duracion = dur;` `this.name = name;` `}` ` ` `public void play(){` ` `` `` `` `` ` `System.out.println("Reproduciendo cancion" + ` `this.name);` ` `` `` ``}` ` ``}` public void play`{` ` `` `` `` `` ` `System.out.println("Reproduciendo album" + ` `this.name + " from " + this.band);` ` `` ``}` ` public Album(String name, String banda){` `this.name = name;` ` `` ` `this.banda = banda;` `}` `}` `public static void main(``String``[] args) {` ` ``Album album = new Album("Perder para Ganar", "Sabino");` ` Album.song song1 = album.new Song(120,"Dale Suave");` ` Album.song song2 = album.new Song(124, "Como Marca el Manual");` ` album.play();` ` song1.play();` ` song2.play();` `}`

Este sería mi código (directamente implementé un método main anidado para no crear otra clase main para ejecutarla):

public class Album {
    private final String name;
    private final String author;
    private final int year;
    private Song[] songs;

    public Album(String name, String author, int year) {
        this.name = name;
        this.author = author;
        this.year = year;
    }

    public static class Song {
        private final String name;
        private final int duration;

        public Song(String name, int duration) {
            this.name = name;
            this.duration = duration;
        }

        public String getName() {
            return name;
        }

        public int getDuration() {
            return duration;
        }

        @Override
        public String toString() {
            return "Song{" +
                    "name='" + name + '\'' +
                    ", duration=" + duration + "s" +
                    '}';
        }
    }
    
    public void setAlbum(Song[] songs) {
        this.songs = songs;
    }

    @Override
    public String toString() {
        return "Album{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", year=" + year +
                ", songs=" + Arrays.toString(songs) +
                '}';
    }

    public static void main(String[] args) {
        Album album = new Album("The songs", "Me", 2023);
        Song[] songs = new Song[3];
        songs[0] = new Song("Song 1", 120);
        songs[1] = new Song("Song 2", 140);
        songs[2] = new Song("Song 3", 110);
        album.setAlbum(songs);
        System.out.println(album);
    }
}
package com.anncode.spotify;

public class Album {
    private String name;
    private String artistName;
    private Integer year;
    private String genre;
    private Album.Song[] songs;

    public Album(String name, String artistName, Integer year, String genre, Album.Song[] songs) {
        this.name = name;
        this.artistName = artistName;
        this.year = year;
        this.genre = genre;
        this.songs = songs;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getArtistName() {
        return artistName;
    }

    public void setArtistName(String artistName) {
        this.artistName = artistName;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }

    public Song[] getSongs() {
        return songs;
    }

    public void setSongs(Song[] songs) {
        this.songs = songs;
    }

    public static class Song {
        private String name;
        private Integer lengthInSeconds;
        private String lyrics;

        public Song(String name, Integer lengthInSeconds, String lyrics) {
            this.name = name;
            this.lengthInSeconds = lengthInSeconds;
            this.lyrics = lyrics;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getLengthInSeconds() {
            return lengthInSeconds;
        }

        public void setLengthInSeconds(Integer lengthInSeconds) {
            this.lengthInSeconds = lengthInSeconds;
        }

        public String getLyrics() {
            return lyrics;
        }

        public void setLyrics(String lyrics) {
            this.lyrics = lyrics;
        }
    }
}

<public class Album { //hacemos la clase que encierra album, debe ser publico para llamarlo
	public static class Song { //hacemos la clase estatica Song que solo se utiliza en Album
		public interface IPlayable { //implementamos un metodo para correr los albumes
			public void play();
		}
	}
	Album album = new Album();  //creamos un nuevo objeto para el album 
	Album.Song song = album.new Song(); //creamos un nuevo objeto accediendo al Album llamado song
}> 
public class Album {

    List<Song> songs;

    public class Song {
        public name;
        public author;
        public duration;

        public play(){
            // Method code
        }
    }

    public addSong(){
        Album.Song song = new Album.new Song();
        song.add(song);
    }

}

Este es mi aporte:


public class Spotify {
    public static void main(String[] args) {

        // #region Adding songs
        Album favoriteAlbum = new Album();
        Collection<Song> myLikedSongs = new HashSet<Song>();

        myLikedSongs.add(
                favoriteAlbum.new Song("Papu Papu", new byte[] { 3, 5, 6, 7 }));

        myLikedSongs.add(
                favoriteAlbum.new Song("La matraka", new byte[] { 3, 5, 6, 7 }));

        myLikedSongs.add(
                favoriteAlbum.new Song("Pa'rriba, pa'bajo", new byte[] { 3, 5, 6, 7 }));

        myLikedSongs.add(
                favoriteAlbum.new Song("Machuca el chile", new byte[] { 3, 5, 6, 7 }));

        myLikedSongs.add(
                favoriteAlbum.new Song("Estoy saliendo con un chavón", new byte[] { 3, 5, 6, 7 }));

        myLikedSongs.add(
                favoriteAlbum.new Song("Se menea, se menea", new byte[] { 3, 5, 6, 7 }));

        favoriteAlbum.setSongs(myLikedSongs);

        Album myAlbum2 = new Album();

        myAlbum2.setSongs(myLikedSongs);

        // #endregion

        playingMySongs(favoriteAlbum);
        playingMySongs(myAlbum2);

    }

    public static void playingMySongs(Album toPlay) {

        System.out.println("\n=====Initializing Album: " + toPlay.getName() + "=====");
        toPlay.getSongs()
                .stream()
                .forEach(e -> {
                    System.out.println(
                            new StringBuilder("\nPlaying the song: ")
                                    .append(e.getName()));

                    try {
                        Thread.sleep(e.getLength() * 1000);
                    } catch (InterruptedException e1) {
                        e1.printStackTrace();
                    }
                });
        System.out.println("\n==================Albums end====================");
    }
}

class Album {

    class Song {
        private String name;
        private byte[] file;
        private long length;

        public Song() {
        }

        public Song(String name, byte[] file) {
            setName(name);
            setFile(file);
            setLength(file.length);
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public byte[] getFile() {
            return file;
        }

        public void setFile(byte[] file) {
            this.file = file;
        }

        public long getLength() {
            return length;
        }

        private void setLength(long length) {
            this.length = length;
        }
    }

    private String name;
    private static AtomicInteger instanceCounter = new AtomicInteger(0);
    private Collection<Song> Songs = new HashSet<Song>();

    public Album() {
        this.name = "My Album " + instanceCounter.incrementAndGet();
    }

    public String getName() {
        return name;
    }

    public Album(Collection<Song> songs) {
        this.setSongs(songs);
    }

    public Collection<Song> getSongs() {
        return Songs;
    }

    public void setSongs(Collection<Song> songs) {
        Songs = songs;
    }

}

Probarlo, quedó divertido.

Esta es la salida:
Imgur

public class Album {

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

	public static class Song {
		/*atributos*/
		private String name;
		private String author;
	}

	public ArrayList<Song> getSongs() {
		return this.songs;
	}

	//etc....
}
public class Album {

    private ArrayList<Songs> songs;
    private String albumName;

    public Album() {
    }

    class Songs {

        String name;
        String time;
    }

}

s

public class Album{
public static class song{
}
}
public class álbum{
	private []Song canciones;
	private String nombreArtista;
	
	public class song{
		private int duracionMin;
		private String nombre;
		public song(int duracionMin, String nombre){
	t	his.duracionMin=duracionMin;
		this.nombre=nombre;
	}
	}
}
public class Album{
public static class Song{
	}
}
public class Album{
	private class Song{
		//Atributos de Song
	}
	private ArrayList<Song> Songs;
}

Aqui mi Codigo

public class Album{
List<Song>
//métodos de album
public static class Song{
metodos de song
}
}

public class Album{
	public class Song{
	}
}
publicclassAlbum{
	publicclassSong{
		
		private String nombre;
		//...etc
	}
	private ArrayList<Song> songs = new ArrayList();
	
	//..Codigo
}```

Mi pregunta es puedo tener una clase protected dentro de la clase album para que esta solo se llame en album? que funcione dentro del album?

 public class  Album{
	  
	  protected class Songs{
	  	private // <Atributos
	  ArrayList<Songs> songs = new ArrayList();	  	
}
	  }

public class Album{
    public class Song{
    ....
    }
}

Album album= new Album();
Album.Song song = song.new Song();

Usando la estructura de una clase anidada - inner.

class album{
static class songs{
}
}

<code>

public class Album {

	public class Song{
		
		private String name;
		private int size;
		
		public Song(String name,String size){
			this.name = name;
			this.size = size;
		}	
	}

	List<Song> song = new ArrayList<>();
	
	song.add(new Song("Hola",5),
			new Song("Bailarina",2));
}
public static Album {
	
public static class song {

	}
}

public class Album
{
	private String alname:
	private String alduration;
	private String Author;
	private class Song
	{
	   private String name;
	   private String duration;
	   private boolean listened;
	}
	private ArrayList<Song> al = new ArrayList();
}

Primero crear la clase ALBUM, despues anidar la clase SONG.

public class Album{
	public static class Song{
		
	}
 }```
public class Album {

	private class Song {
		String[] singers;
		short duration;
		String name;
		
		public void play() {
			System.out.println("Playing the song");
		}
	}
	
	String mainSinger;
	String Name;
	ArrayList<Song> songs;
	
	public void play(int song) {
		songs.get(song).play();
	}
}

Me qeudo la duda, es mejor dejar la clase Song como static? vi que la mayoria de usiarios la declararon static.

al entrar a esta pagina me sale esto, no se si es normal?

b'
Spotify tiene una relaci\xc3\xb3n Album - Song en donde Song ser\xc3\xa1 una clase que solo es utilizada en Album pues la definici\xc3\xb3n de este es una colecci\xc3\xb3n de Song\xe2\x80\x99s.

\r\n```

![](

import java.util.ArrayList;
import java.util.List;

public class Album{
    private List<Song> songs = new ArrayList();

    private class Song{
        private String nombre;
    }
}
public class Album{
	private List<Song> songs = new ArrayList();
	public static class Song{
		private String nombre;
	}
}
public class Album {
	
	Album album = new Album();
	Album.Soung soung = album.new Soung();
	
	public class Soung {
		
		String [] soung;

		public String[] getSoung() {
			return soung;
		}

		public void setSoung(String[] soung) {
			this.soung = soung;
		}
		
		
	}
	
	
	
}
public class Album{
private class Song {
}
}
package com.sroba.spotify;

import java.util.List;

public class Album {
	
	private String nombreAlbum;
	private String nombreArtista;
	private String anoCreacion;
	
	public static List<Song> songs;
	
	public class Song{
		
		private String nombreSong;
		private int duracion;
	}
}
public class album{
	public static class song{
	} 
}

public class Album {

private String nombre;
private String artista;
private String an_o;
private ArrayList<Song> songs;

class Song{
	
	private String nombre;
	private int duracion;
}

}

public class Album{
	public static class Song{
	}
}
<code>
public class Album{
	public class Song{
		.....
	}
}

Album album = new Album();
album.Song song = album.new Song();
public class Album {
	public class Song {
		void cancion() {
			System.out.println("London Calling.");
		}
	}
}
public class ClaseAnidada {
	public static void main(String[] args) {
		Album album = new Album();
		Album.Song song = album.new Song();

		song.cancion();
	}
}
<code>public  class Album{
	
		public class Song{
	
		}

}
public class Album {
	private String nombre;

	private static void class Song{
	//Instrucciones
		private void method(){
		//method implementation
		}
	}
}```

Les dejo el codigo que realice

package com.codecasales.spotify;

import java.util.ArrayList;

public class Album {
	ArrayList<Song> songs = new ArrayList<Song>();
	
	public void addSong(String nombre, String Artist, float duration, int id) {
		//Implementacion
	}
	
	public void reproducir(Song song){
		System.out.println("Estas escuchando: ");
		System.out.println(song.name);
	}
	
	private class Song{
		String name;
		float duration;
		String artist;
		int id;
		
		Song(String name, float duration, String artist, int id){
			this.name = name;
			this.duration = duration;
			this.artist = artist;
			this.id = id;
		}
	}
	
}

Utilizar clases anidadas, y ademàs se puede la clase principal ALBUM, puede tener un atributo que seria un arrayList de SONG,

<<public class Album{
	private static class Song{

	public void tonaso(){
		String [] musica={"Trance","Salsa","Bacahata"};
		for(String music : musica){
		System.out.println(music);
							}
					}
 public void mimusica(){
	Song.tonaso tono=new Son.tonaso();
}
}

>
public class Album{
	public class Song{
	
	}
}

Album album = new Album();
album.Song song = album.new Song();```
public class Album {

       public class Song{
       /*
       *atributos
       *
       */
			}
}

Mi respuesta al reto es la siguiente:

La relación entre Album - Song es de tipo Clase anidada - Inner.

public class Album {
//…
	private class Song {
	//…
	}
}```
package com.tom.amazonviewer;

import java.util.ArrayList;

public class Album{
	
	private String artista;
	private int anio;
	private String genero;		
	private ArrayList<Song> songs = new ArrayList();	
	
	public class Song{	
		private String nombre;
		private int DuracionSeg;		
	}	
}```
public class Album{
   public static class Song {
    }
}

Yo lo pienso así

public class Album{
	//TODO CODE HERE
	
	class Song{
	
	//TODO CODE HERE
	}
}

Album album = new Album();
	Album.Song  aSong = album.New Song();

public class Album {
public class Song {
private Strin nombre;
}
ArrayList<Song> songs = new ArrayList();
}

public class Album {
public class Song {
private String nombre;
}
ArrayList<Song> songs = new ArrayList();
}

public class Album{
int id
String titulo
short año
String genero
ArrayList <Song> songs;

public class Song{
int ISRC
String titulo
int duracion
String formato
int pista
String Colaboradores
public static ArrayList<Songs> makeSongList(){
....
return songs;
void hear();
.....
}
public static ArrayList<Album> makeAlbumsList(){
......
return albums;
}
}
 }
<code>
public class Album {

	Song s= new Song();
	
	private class Song{
		
	}
	
}
public class Album {

	public class Song {


	}
}
public class Album{
	//Atributos y metodos Album
	private class Song{
		//Atributos y metodos de Song solo accesibles desde la clase album
	}
}```
public class album{
	private List<song> canciones;

	public class song{
		private String nameSong;
		//Atributos
		// Metodos Get y Set
	}
}
public class Album {
	private Song[] songs;
	public class Song {
	}
}

public class Album
{
public static class Song
{
}

}

public class Album{
public static class Song{
 }
}

public class Album {
public class Song {//clase anidada

}	

}

import java.util.*;

public class Album {

private List<Song> albumColeccion;

public Album() {
    albumColeccion = new ArrayList<>();
  
}
public void add (Song cancion){
    albumColeccion.add(cancion);
   
}
public Song get (int a){
    return albumColeccion.get(a);
}
public int size(){
    return albumColeccion.size();
}



public static class Song{

    protected static String artista ="";
    protected static String nombreSong="";
    protected static double duracionMinSeg=0;

    public Song(String artista, String nombreSong, double duracionMinSeg) {
        this.artista = artista;
        this.nombreSong = nombreSong;
        this.duracionMinSeg = duracionMinSeg;
    }
}}
public class Album{
	class Song{
		//Definición de métodos y datos.
	}

	public ArrayList <Song> songs = new ArrayList();
}
class Album {
	
	static class Song {

	}
}
public class Album{
	public static class Song{
}
}
public class Album{
	//Otros atributos
	public class Song{
		//Atributos de songs
	}
}
import java.util.ArrayList;

public class Album {

    private static ArrayList<Album.Song> songs;

    public static class Song{
        private String nombre;

        public Song(String nombre){
            this.setNombre(nombre);
        }

        public String getNombre(){
            return nombre;
        }

        public void setNombre(String nombre){
            this.nombre = nombre;
        }
    }

    public static void main(String[] args){
        songs = new ArrayList();
        for(int i=1;i<=10;i++) {
            addSong(new Album.Song("Canción " + i));
        }
    }

    public static void addSong(Album.Song cancion){
        songs.add(cancion);
    }
}

Les paso mi código espero que este bien, cualquier corrección me avisan…

public class Album {
	void run() {
		class Song {
			public void setSongs(String cancion1, String cancion2) {
				String[] objString = new String[8];
				objString[0] = cancion1;
				objString[1] = cancion2;
				System.out.println(objString[0]);
				System.out.println(objString[1]);
			}
		}
		// Crea la instancia de Song y le pasa los temas
		Song objSOng = new Song();
		objSOng.setSongs("Quita Penas", "El meneaito");
	}

	public static void main(String[] args) {
		Album objAlbum = new Album();
		objAlbum.run();
		/* Imprime la colección de temas
		 * Quita penas
		 * El meneaito
		*/
	}

}
class Album{

	public class Song{

		}

}

Porfa Debería alguien responder a algún comentario para que sepamos cuál es la solución correcta.

publicclassAlbum{
/**
* <h1>Song</h1>
*
* Representa una canción de Spotify, con nombre, duracion y demas atributos
*/
publicclassSong{

	private String nombre;
	//...otros atributos
}
private ArrayList<Song> songs = new ArrayList();

//..logica para clase albun.

}

😃

public class Album{
	
	public List<Song> getSongs(){
		List<Song> songs = new ArrayList<>();

		Song song1 = new Song();
		song1.setName("La primavera");
		songs.add(song1);

		Song song2 = new Song();
		song2.setName("Tratame suavemente");
		songs.add(song2);

		Song song3 = new Song();
		song3.setName("Persiana americana");
		songs.add(song3);

		return songs;
	}

	public class Song{
	
		private String nombre;

		public String getNombre(){
			return nombre;
		}

		public void setNombre(String nombre){
			this.nombre = nombre;
		}
	}
}
public class Album{
	public static classSong{
	}
}```

Si estrictamente Song es solo utilizada en album mi solucion seria asi:

public class Album {
	
	public Album(String ... songs) {
		int size = songs.length;
		this.songs = new Song[size];
		for(int i = 0; i < size; i++) {
			this.songs[i] = new Song(songs[i]);
		}
	}
	
	private Song[] songs;
	
	private class Song {
		private String name;
		public Song(String name) {
			this.name = name;
		}
	}
	
	public void printSongs() {
		for(Song s : this.songs) {
			System.out.println(s.name);
		}
	}

}

Tanto el atributo songs como la clase interna Song son privadas ya que esa es la condicion que se planea.

Para probarla creo un album y lo imprimo:

Album a = new Album("Animal", "The Seed", "Lucky");
a.printSongs();

Y el resultado que obtengo es :

Animal
The Seed
Lucky

Nota: Se que tanto para el argumento del constructor Album y su atributo “songs” uso el mismo nombre, pero al ser un ejemplo pequeño creo con el “this.” no se pierde tanto la legibilidad.

public class Album{
static class song{
metodos(){
}
metodo_statico(){
}
}
metodos(){
}

Album album=new Album();
album.Song = new album.Song();
Song.metodo_estatico();

}

public class Album
{
//instructions code here
public static class Song(){
//instruction code and method here
}
}

package spotify;

import java.io.File;
import java.util.Date;
import java.util.List;

public class Album {
	
	private List<Song> songs;
	private String singer;
	private Date publishDate;
	
	class Song
	{
		private String letter;
		private Integer duration;
		private File file;
		private String composser;
		
		
		public String getLetter() {
			return letter;
		}
		public void setLetter(String letter) {
			this.letter = letter;
		}
		public Integer getDuration() {
			return duration;
		}
		public void setDuration(Integer duration) {
			this.duration = duration;
		}
		public File getFile() {
			return file;
		}
		public void setFile(File file) {
			this.file = file;
		}
		public String getComposser() {
			return composser;
		}
		public void setComposser(String composser) {
			this.composser = composser;
		}
	}
	
	public String getSinger() {
		return singer;
	}
	public void setSinger(String singer) {
		this.singer = singer;
	}
	public List<Song> getSongs() {
		return songs;
	}
	public void setSongs(List<Song> songs) {
		this.songs = songs;
	}
	public Date getPublishDate() {
		return publishDate;
	}
	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}
}

`public class Album {
private ArrayList<Song> songs = new ArrayList<Song>();

//Contructor
public Album(){
	//Default Constructor
}

//Getters and Setters

private class Song {
	private String artist;
	private int  duration;
	private String genre;
	private int year;

	//Constructor

	//Getters And Setters
}

}`

import java.util.List;

public class Album{
private List<Song> songs;

classSong{ }

}

Reto completado:

import java.util.ArrayList;

public class Album {

    private String name;
    private Band band;
    private ArrayList<Song> songs;
    
    public class Song {
        
        void playSong(){
            
        }
        
        void stopSong(){
            
        }
    }
}

package com.davidcode.holamundo;

import java.util.ArrayList;

public class Album {

private String nameList; 
private ArrayList<ListSongs> listSongs ; /// no estoy seguro del ArrayList

 class Song {
	 
	private  Integer duration;
	private String author;
	private int  ano;
	private String name;
	
}

}

public class Album{
    private ArrayList<Song> songList = new ArrayList();

    public void addSong(String name){
        songList.addSong(new Song(name));
    }


    private  class Song{
        private String name;        
            
        public Song(String name){
            this.name = name;
        }
        public void setName(String name){
            this.name = name;
        }

        public String getName(){
            return name;
        }
    }
}```
public class Album{
    private ArrayList<Song> songList = new ArrayList();

    public void addSong(String name, String lyrics){
        songList.addSong(new Song(name, lyrics));
    }

    public ArrayList<song> getSongList(){
        return songList;
    }


    private static  class Song{
        private String name;
        private String lyrics;
            
        public Song(String name, String lyrics){
            this.name = name;
            this.lyrics = lyrics;
        }
        public void setLyrics(String lyrics){
            this.lyrics = lyrics;
        }

        public void setName(String name){
            this.name = name;
        }


        public String getName(){
            return name;
        }

        public String getLyrics(){
            return lyrics;
        }
    }
}```
public class Album {

    public class Song {

    }

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

Crear una clase anidada
public Class Album{
class Song(){
}
}

la clase Albun contendria una clase statica de song la cual tendria el metodo de coleecionsong y asi poder solo usar en los albunes que la relacionen. se de instanciar desde el metodo de la clase externa para el uso de los variables de la clase superior.

//clase exterior
public class Album{

		String collectionSong ="";
		public Album(coleccionSong){
			//constructor
		}

		//clase interior
		public static class song{
			void collectionSong(){
				//instanciando la clase externa
				Album album = new Album();
				//coleccion de canciones
				System.out.prinnl(Album.collectionSong);
			}
		}
}

import java.util.ArrayList;

public class Album {

public static class Song {
    public int n = 5;
    ArrayList<String> arrli = new ArrayList<String>(n);


    public void setCancion() {

        for (int i = 1; i <= n; i++) {
            arrli.add("cancion " + i + ": ");
        }

        for (int j = 0; j < arrli.size(); j++) {
            System.out.print(arrli.get(j) + " ");
        }

    }
}

}

class ClaseAnidadaAlbum {
public static void main(String[] args) {
// Album album= new Album();
Album.Song song = new Album.Song();

    song.setCancion();

}

}