Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: Define the new class type: Queue using a singly linked list. Define the new class type: Jukebox which creates three objects of type Queue

Objectives:

  • Define the new class type: Queue using a singly linked list.
  • Define the new class type: Jukebox which creates three objects of type Queue class.
  • Practice enqueue-ing and dequeue-ing elements from the top of your singly linked list Queue class.
  • Test the implementation of the class: MyTunes.

The class files are here: https://drive.google.com/file/d/1yCCQeZCS-uLoL_CK0Et9dX-KCaokXQxR/view?usp=sharing

class MyTunes

Creates an object of type MyTunes class that partially simulate the digital jukebox TouchTunes, using a queue which holds playlist. Tests the implementation of your Queue and Jukebox classes.

From main your program:

  • Starts by creating an object of type MyTunes which initializes three playlists favoritesPL, loungePL, and roadTrip by reading the input file "tunes.txt" which contains one type of line entry:
    • playlist songTitle Indicates that the user wants to add a SongEntry object with a specific songTitle to the playlist .
  • Then it prompts the user for total songs they want to play.
  • It simulates playing one song at a time from each playlist until either:
    • we've played the total requested number of songs;
    • or all playlists are empty.
  • Reminder: in a queue data structure we process items in FIFO (First-In-First-Out) order.

class Jukebox

Define the class Jukebox to manage three objects of type Queue. The class Jukebox manages three objects of type Queue. An instance of the class may read a file which includes the user's requests for a the name of a song to be added to a specific playlist. It will then add songs to the three playlists "favorites", "lounge", and "road trip" accordingly.

Attributes:

  • A variable called favoritePL of type Queue which simulates the playlist referred to as "favorites" in the input file.
  • A variable called roadTripPL of type Queue which simulates the playlist referred to as "road trip" in the input file.
  • A variable called loungePL of type Queue which simulates the playlist referred to as "lounge" in the input file.

Methods:

  • A method called fillPlaylists() reads the test file and then adds songs to one of the three queues. For example, if the file contains line:

    favorites,title 

    Then the first song found that equals the title will be placed in the favorites playlist.

  • Accessor methods getFavoritePL(), getRoadTripPL() and getLoungePL() for each of the three queue structures favoritePL, roadTripPL and loungePL respectively.

class Queue

Define the parameterized class Queue which implements Iterable. Objects of type Queue manage items in a singly linked list where we can enqueue() items to the end and dequeue() items from the front of the queue.

Attributes:

  • A variable called name of type String for the name of this instance. We we will use this for testing and debugging purposes.
  • A variable called head, which points to the front of the queue.
  • A variable called tail, which points to the end of the queue.

Methods:

  • A constructor that takes in a user assigned name and initializes the class attributes.
  • A method called enqueue() which takes a generic item as the argument and adds the item to the end of the queue.
  • A method called dequeue() which receives no arguments and removes the item from the front of the queue. This method should return the generic item dequeue-ed. This method should throw an NoSuchElementException if the queue is empty.
  • A method called peek which looks at the least recently added item of the queue and returns an object of the generic type for the data seen at the front of the queue. The item should not be removed from the front of the queue. NOTE: If the queue is empty, returns null.
  • The methods isEmpty(), size() and toString() method.

Input File Format:

The format of the "tunes.txt" input file is:

favorites,Shadows - Original road trip,Tom's Diner favorites,Take Me Away road trip,Here With Me lounge,Nuvole Bianche lounge,Luka favorites,Stoned road trip,Get Happy favorites,We Belong road trip,Let's Dance road trip,Oh What a Feeling favorites,Stairway To The Stars road trip,Separate Ways (Worlds Apart) road trip,Road Home lounge,Traffic 

Output of example 1 showing non-empty queues:

Welcome! We have over 59600 in FoothillTunes store! Total number of songs in playlists: 16 Songs in each playlist: favorites: [Shadows - Original, 0:0:25, Blue Oyster Cult, classic pop and rock; Take Me Away, 0:4:32, Blue Oyster Cult, classic pop and rock; Stoned, 0:11:47, Dido, classic pop and rock; We Belong, 0:3:43, Pat Benatar, classic pop and rock; Stairway To The Stars, 0:3:46, Blue Oyster Cult, classic pop and rock] lounge: [Solo, 0:4:41, Working Week, classic pop and rock; Nuvole Bianche, 0:5:58, Ludovico Einaudi, classical; Luka, 0:3:52, Suzanne Vega, classic pop and rock; Traffic, 0:4:5, Dawn Landes, classic pop and rock] road trip: [Tom's Diner, 0:2:40, Suzanne Vega, classic pop and rock; Here With Me, 0:4:41, Dido, classic pop and rock; Get Happy, 0:6:36, Jean Knight, classic pop and rock; Let's Dance, 0:2:45, Jake Shimabukuro, folk; Oh What a Feeling, 0:3:42, Gregory Isaac, classic pop and rock; Separate Ways (Worlds Apart), 0:5:25, Journey, classic pop and rock; Road Home, 0:5:8, The String Cheese Incident, folk] Enter your the number of songs you would like to play: 7 Playing 7 number of songs... Playing song title "Shadows - Original" Playing song title "Solo" Playing song title "Tom's Diner" Playing song title "Take Me Away" Playing song title "Nuvole Bianche" Playing song title "Here With Me" Playing song title "Stoned" Checking the size of each playlist: Playlist "favorites" is 2 song(s) remaining. Playlist "lounge" is 2 song(s) remaining. Playlist "road trip" is 5 song(s) remaining. Songs in each list: favorites: [We Belong, 0:3:43, Pat Benatar, classic pop and rock; Stairway To The Stars, 0:3:46, Blue Oyster Cult, classic pop and rock] lounge: [Luka, 0:3:52, Suzanne Vega, classic pop and rock; Traffic, 0:4:5, Dawn Landes, classic pop and rock] road trip: [Get Happy, 0:6:36, Jean Knight, classic pop and rock; Let's Dance, 0:2:45, Jake Shimabukuro, folk; Oh What a Feeling, 0:3:42, Gregory Isaac, classic pop and rock; Separate Ways (Worlds Apart), 0:5:25, Journey, classic pop and rock; Road Home, 0:5:8, The String Cheese Incident, folk] Done with MyTunes. 

Output of example 2 with input test file "tunes_truncated.txt" where some queues are empty when calling dequeue() method of class Queue:

Welcome! We have over 59600 in FoothillTunes store! Total number of songs in playlists: 3 Songs in each playlist: favorites: [Shadows - Original, 0:0:25, Blue Oyster Cult, classic pop and rock] lounge: [Solo, 0:4:41, Working Week, classic pop and rock] road trip: [Tom's Diner, 0:2:40, Suzanne Vega, classic pop and rock] Enter your the number of songs you would like to play: 4 Playing 4 number of songs... Playing song title "Shadows - Original" Playing song title "Solo" Playing song title "Tom's Diner" Checking the size of each playlist: Playlist "favorites" has *no* songs remaining. Playlist "lounge" has *no* songs remaining. Playlist "road trip" has *no* songs remaining. Songs in each list: favorites: [ ] lounge: [ ] road trip: [ ] Done with MyTunes.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

(2) f YZ (y, z).

Answered: 1 week ago

Question

Explain how HR serves as a strategic business partner.

Answered: 1 week ago

Question

Describe a social audit.

Answered: 1 week ago

Question

Describe ethics training.

Answered: 1 week ago