Java代写:CS1557 My Tunes

这次需要代写的作业,是一个类似digital jukebox TouchTunes的程序。

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.

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 Queue

Define the parameterized class Queue which implements Iterable. Objects of type Queue manage items in a singly linked list where we can enqueue() from the front and dequeue() items from the end 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 NullPointerException if the queue is empty.
  • A method called peek which looks at the least recently added item of the queue and returns a 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.

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:

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"

Additional Requirements

Your program must read input from files located in a directory called “resources”. Make sure to use relative path instead of specifying the entire path.

  • Show enough runs to prove your data structures work, and show at least one run where you are trying to remove items from an empty queue. Modify the test file to include additional test cases.

FAQ: How do I read user input?
You must read the input a text file matching the provided format. See Additional Requirements section.

FAQ: Can I include additional test runs?
Yes.

FAQ: Does my output have to match the example output?
Your output must include the name of the Queue object. This should have been initialized in our Queue constructor.
Otherwise, your output style can be different from mine, as long as it is contains equivalent information and is easy to understand.
However, the format of your input files must match. Otherwise, I will not be able parse and therefore grade your submission.

FAQ: Can I submit more than once?
Yes, make sure to create and test one feature at a time, however small…rather than implementing a lot of code that you never test.
If your implementation so far compiles and runs successfully, commit to your repo. Then, continue working on the next feature.

FAQ: Can I include additional attributes, methods and or classes?
You are welcome to create as many classes and methods as you need with the restriction that your implementation will still successfully compile and run with the given original test files. See project 1 FAQs for more details.

FAQ: Is the previous assignment needed for this project?
No, this assignment does not build on top of the previous project.

FAQ: Do I need to build my own Singly Linked List?
Yes, build your own singly linked list.

Suggestion: Implement your Queue class to extend from LinkedList class. Then, override the appropriate methods such as queue(), dequeue(), etc.

NOTE: The implementation provided for FHarrayList and FHlinkedlist is a doubly linked list implementation and not efficient for the queue data structure we need for our project. So, use the FHLinkedList provided as a reference. However, do NOT implement a doubly linked list version. Instead implement your own version of a queue structure.

Please note that if you use the one provided by the Java library, your implementation of this project would be considered incomplete.

In order to receive full credit on this assignment, your program must

  1. Follow all Program Guidelines, see Modules for the guidelines.
  2. Get the correct results when the main() is run in MyTunes.
  3. Include the following in your lab submission:
    • The source code: the listing of your program under the “src” directory;
    • Comment all class and all method. Then, generate Javadocs and include it in your submission. Reminder: A brief tutorial on generating Javadocs is included in the Introudctions module section Example Program Submission.
    • Run output sample(s): in a plain­text file called RUN.txt under the resource folder in the top­level directory of your project. (For now, the output should be only plain­text);
    • A brief description of all files submitted: in a plain­text file called README.txt.