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/39

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.

open-graph-default.png

¿Cuál sería la forma más adecuada de tratar la clase Song si esta solamente se utilizará en Album?

Realiza el código que resuelva esto y compartelo en la sección de discuciones.

Aportes 114

Preguntas 2

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.

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();

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

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

}
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 {
	//…
	}
}```

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

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();

}

}

`

public class Album {

	ArrayList<Song> songs;

	public class Song{

	}
}

`

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

ArrayList<Song> songList = new ArrayList<>();
}```
import java.util.ArrayList;

public class Album {
    private ArrayList<Song> songs;

    Album(){
        songs = new ArrayList<>();
    }

    class Song {

    }

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

    public void setSongs(ArrayList<Song> songs) {
        this.songs = songs;
    }
}


Imagino que debería ser algo así !?

public class Album(){
	public class Song(){
		//contenido....
	}
}```
import java.util.List;

public class Album {
	private List<Song> songs;
	
	class Song{ }
}

PRIMERO, CREAR LA CLASE ALBUM Y DENTRO DE ALBUM CREAR SONGS
package spotify;

import java.util.ArrayList;

public class Album {

public String nombreAlbum;
public String cantante;
public String casaDiscografica;
public ArrayList<Songs> songs;

public class Songs {

    public String nombreCancion;
    public String interprete;
    public String compositor;
    public float duracion;
    
    public void songs(String nombreCancion, String interprete){
        this.setNombreCancion(nombreCancion);
        this.setInterprete(interprete);
    }

    public String getNombreCancion() {
        return nombreCancion;
    }

    public void setNombreCancion(String nombreCancion) {
        this.nombreCancion = nombreCancion;
    }

    public String getInterprete() {
        return interprete;
    }

    public void setInterprete(String interprete) {
        this.interprete = interprete;
    }

    public String getCompositor() {
        return compositor;
    }

    public void setCompositor(String compositor) {
        this.compositor = compositor;
    }

    public float getDuracion() {
        return duracion;
    }

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

}

LUEGO, LLAMAR A SONG DESDE EL METODO MAIN

package spotify;

public class Spotify {

public static void main(String[] args) {
    // TODO code application logic here
    
    Album album = new Album();
    Album.Songs song = album.new Songs();
    song.songs("Lost on you", "LP");
    System.out.println(song.getInterprete());
    System.out.println(song.getNombreCancion());
}

}

RESULTADO:
LP
Lost on you

Hola podrian decirme si esta bien aplicado?

public class Album {
    public static void main(String[] args) {
        Album album = new Album("Arjona","Circo de soledad");
        album.addSongs("Ella",4.22F);
        album.addSongs("Señorita", 3.22F);
        System.out.println("El Album " + album.getName() + " de Artista " + album.getArtist() + " tiene estas canciones");
        for (int i = 0; i < album.getSongs().size() ; i++) {
            System.out.println(album.getSongs().get(i).getTitle() + " con una duracion de " +
                    album.getSongs().get(i).getTime() + " min");
        }
    }
    private String artist;
    private String name;
    public ArrayList<Song> songs = new ArrayList<>();

    public Album(String artist, String name) {
        this.artist = artist;
        this.name = name;
    }

    public String getArtist() {
        return artist;
    }

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

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

    public void addSongs(String title,Float time) {
        songs.add(new Song(title,time));
    }

    public String getName() {
        return name;
    }

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

    public static class Song{
        private   String title;
        private   Float time;

        public Song(String title, Float time) {
            this.title = title;
            this.time = time;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public Float getTime() {
            return time;
        }

        public void setTime(Float time) {
            this.time = time;
        }
    }
}

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

private class Song {

}

}

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