Java - TP3

Multimedia player
Author

Ludovic Deneuville

Ideas of Questions:

  • About Stream
  • pitest
  • Interface?

1 Instructions

This lab will be covered in practical sessions 3 and 4.

1.1 Launch service VSCode Java

1.2 Update your repository

Perhaps the repository used as a template has been updated since the last practical session.

1.3 Open Folder

In VSCode :

    • or using: code-server ~/work/ENSAI-2A-Java-TP/tp3/

tp3 must be the root folder in your explorer.

1.4 When you’ve finished

2 Subject

This exercise involves designing and implementing a media management system in Java. You’ll create classes for media types (songs, podcasts), playlists, and a media player. Focus on object-oriented principles, defining attributes, methods, and relationships. The goal is a functional system for managing and playing media.

Given files: Song.java and pom.xml

3 Questions

3.1 Artist

In the Song class, we want to replace the String types for attributes singer, author, and composer with instances of an Artist class.

classDiagram

class Artist {
     - -firstName: String
     - -lastName: String
     - -nationality: String
     + toString(): String
}

In the toString() method, concat “Artist” with firstName and lastName.

    • We’ll assume that the songs have a single singer, a single author, a single composer
    • this method will print each word of lyrics
    • use the code below to add a brief delay between each word
try {
    Thread.sleep(100);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    System.err.println("Thread was interrupted");
}
    • use a real Song, singer and lyrics
    • you are allowed to leave author and composer blank
    • for the lyrics, you can limit them to a few hundred words

3.2 Podcast

In your player you will also read Podcasts :

classDiagram

class Podcast {
    - -title: String
    - -host: String
    - -topic: String
    - -duration: int
    - -year: int
    - -subtitles: String
    + play()
}

    • Use OOP to avoid code duplication
    • Bonus: You will notice that this method is very similar to Song’s. Isn’t there a better way?

3.3 Pop, Rock, Electro

We want to add a new attribute to the Song to store the musical genres it is associated with.

3.4 Playlist

We now want to be able to create playlists with these songs and podcasts.

classDiagram

class Playlist {
    - -name: String
    - -mediaList: List~Media~
    - -totalDuration: int
    + addMedia(Media media)
    + removeMedia(Media media): bool
    + removeMedia(int index)
    + play(boolean random)
}

    • it deletes occurences of a media if it exists in the playlist
    • Include a parameter to play the tracks randomly

3.5 Create some objects

In the main method: