Microsoft Word - COMP1406-W22-T0607.docxXXXXXXXXXXCOMP 1406 B/C/D – Winter 2023 – Tutorial #6/# XXXXXXXXXXDue Friday, March 10th, 11:59pm COMP 1406 Winter XXXXXXXXXXTutorial #6/#7 ...




I need help with this. No matter what I do i cant complete it and Im really low on time. I would normally never resort to something like this but due to medical reasons I really need to. This pdf is the instructions the zip is the initial code.






Microsoft Word - COMP1406-W22-T0607.docx COMP 1406 B/C/D – Winter 2023 – Tutorial #6/#7 Due Friday, March 10th, 11:59pm COMP 1406 Winter 2023 - Tutorial #6/#7 Objectives • Practice working with Lists • Practice working with Maps • Practice using the Java Collections class Getting Started: Download the Tutorial 0607.zip file from Brightspace. This file contains an IntelliJ project with the starting resources for this tutorial. In this tutorial, you will simulate an on-line music centre called the MusicExchangeCenter where Users log in and download Songs from other users’ computers. It is a similar idea to the operation of the original Napster program that operated many years ago where users shared songs. You won’t be doing any downloading or internet programming. Instead, you will just simulate what happens in real life. The tutorial will give you familiarity with Lists and Maps. (1) The Song/ User Classes The Song and User classes represent a song that is available at the Music Exchange Center and a user of the Music Exchange Center that logs in to download music. Do the following in the User class: Add a songList attribute which is a List of Song objects. This list will contain all the songs that this user has on his/her hard drive to be made available to the Music Exchange Center community. Adjust the 2nd constructor to ensure that this attribute is initialized properly. Write a get method for the attribute as well. Adjust the toString() method so that the XXX is replaced by the number of songs available in the user’s song list. Create a method called addSong(Song s) which adds a given song to the user’s song list. Create a method called totalSongTime() that returns an integer indicating the total duration (i.e., amount of time), in seconds, that all of the user’s songs would require if played. COMP 1406 B/C/D – Winter 2023 – Tutorial #6/#7 Due Friday, March 10th, 11:59pm (2) The MusicExchangeCenter Class Implement a class called MusicExchangeCenter which represents the company website that users log in and out of in order to download music. The class should have this attribute: users – a List of all registered Users (which may be either logged on or not logged on). Create the following methods: A zero-parameter constructor that sets attributes properly. An onlineUsers() method that returns a List of all Users that are currently online. Note that this method creates and returns a new list each time it is called. An allAvailableSongs() method that returns a new List of all Songs currently available for download (i.e., all songs that are available from all logged-on users). Note that this method creates and returns a new list each time it is called. A toString() method that returns a string representation of the music center showing the number of users currently online as well as the number of songs currently available. (e.g., "Music Exchange Center (3 users online, 15 songs available)"). A userWithName(String s) method that finds and returns the User object with the given name if it is in the list of users. If not there, null should be returned. A registerUser(User x) method that adds a given User to the music center’s list of users, provided that there are no other users with the same userName. If there are other users with the same userName, then this method does nothing. Use the userWithName(String s) method above. An availableSongsByArtist(String artist) method that returns a new List of all Song objects currently available for download by the specified artist. Note that this method creates and returns a new list each time it is called. Go back to the User class and add these methods: A register(MusicExchangeCenter m) that makes use of the registerUser(User x) method that you just wrote to register the user into the given MusicExchangeCenter m. A logon() method that simulates a user going online. A logoff() method that simulates a user going offline. Now you should test your code. To do so, run the MusicExchangeTestProgram.java file and compare your results to the expected results below. COMP 1406 B/C/D – Winter 2023 – Tutorial #6/#7 Due Friday, March 10th, 11:59pm Here is the output that you should see: Status: Music Exchange Center (0 users on-line, 0 songs available) On-Line Users: [] Available Songs: [] Status: Music Exchange Center (2 users on-line, 8 songs available) On-Line Users: [Disco Stew: 4 songs (online), Ronnie Rocker: 4 songs (online)] Available Songs: ["Hey Jude" by The Beatles 4:35, "Barbie Girl" by Aqua 3:54, "Only You Can Rock Me" by UFO 4:59, "Paper Soup Cats" by Jaw 4:18, "Rock is Cool" by Yeah 4:17, "My Girl is Mean to Me" by Can't Stand Up 3:29, "Only You Can Rock Me" by UFO 4:52, "We're Not Gonna Take It" by Twisted Sister 3:9] Status: Music Exchange Center (4 users on-line, 16 songs available) On-Line Users: [Disco Stew: 4 songs (online), Ronnie Rocker: 4 songs (online), Country Candy: 3 songs (online), Peter Punk: 5 songs (online)] Available Songs: ["Hey Jude" by The Beatles 4:35, "Barbie Girl" by Aqua 3:54, "Only You Can Rock Me" by UFO 4:59, "Paper Soup Cats" by Jaw 4:18, "Rock is Cool" by Yeah 4:17, "My Girl is Mean to Me" by Can't Stand Up 3:29, "Only You Can Rock Me" by UFO 4:52, "We're Not Gonna Take It" by Twisted Sister 3:9, "If I Had a Hammer" by Long Road 4:15, "My Man is a 4x4 Driver" by Ms. Lonely 3:7, "This Song is for Johnny" by Lone Wolf 4:22, "Bite My Arms Off" by Jaw 4:12, "Where's My Sweater" by The Knitters 3:41, "Is that My Toenail ?" by Clip 4:47, "Anvil Headache" by Clip 4:34, "My Hair is on Fire" by Jaw 3:55] Available Songs By Jaw: ["Paper Soup Cats" by Jaw 4:18, "Bite My Arms Off" by Jaw 4:12, "My Hair is on Fire" by Jaw 3:55] Status: Music Exchange Center (2 users on-line, 9 songs available) On-Line Users: [Ronnie Rocker: 4 songs (online), Peter Punk: 5 songs (online)] Available Songs: ["Rock is Cool" by Yeah 4:17, "My Girl is Mean to Me" by Can't Stand Up 3:29, "Only You Can Rock Me" by UFO 4:52, "We're Not Gonna Take It" by Twisted Sister 3:9, "Bite My Arms Off" by Jaw 4:12, "Where's My Sweater" by The Knitters 3:41, "Is that My Toenail ?" by Clip 4:47, "Anvil Headache" by Clip 4:34, "My Hair is on Fire" by Jaw 3:55] Available Songs By Jaw: ["Bite My Arms Off" by Jaw 4:12, "My Hair is on Fire" by Jaw 3:55] Status: Music Exchange Center (0 users on-line, 0 songs available) On-Line Users: [] Available Songs: [] Available Songs By Jaw: [] (3) Downloading Music Go back to the Song class and add to it an attribute called owner which will be a User object representing the user who happens to own this copy of this song. Note that a Song object may only be owned by one User and that many users can have copies of the same song. Set it to null initially. In the User class, adjust the addSong(Song s) method so that it sets the owner properly. In the User class, add a method called requestCompleteSonglist(MusicExchangeCenter m). This method should gather the list of all available songs from all users that are online at the given music exchange center (i.e., the union of all of their local song lists), and then return a List formatted as follows (note: there should be 1 String element in the list per line): COMP 1406 B/C/D – Winter 2023 – Tutorial #6/#7 Due Friday, March 10th, 11:59pm TITLE ARTIST TIME OWNER 1. Hey Jude The Beatles 4:35 Disco Stew 2. Barbie Girl Aqua 3:54 Disco Stew 3. Only You Can Rock Me UFO 4:59 Disco Stew 4. Paper Soup Cats Jaw 4:18 Disco Stew 5. Rock is Cool Yeah 4:17 Ronnie Rocker 6. My Girl is Mean to Me Can't Stand Up 3:29 Ronnie Rocker 7. Only You Can Rock Me UFO 4:52 Ronnie Rocker 8. We're Not Gonna Take It Twisted Sister 3:09 Ronnie Rocker Notice that the songs are numbered and that the title, artist, time and owner are all lined up nicely. You should use the String.format() method as described in the notes (Chapter 1). Recall that %-30s in the format string will allow you to display a left- justified 30-character string. Also, %2d and %02d will allow you to display numbers so that they take 2 places, with the 0 indicating that a leading zero character is desired. In the User class, add a method called requestSonglistByArtist(MusicExchangeCenter m, String artist). This method should gather the list of all available songs by the given artist from all users that are online at the given music exchange center (i.e., the union of all of their local song lists), and then return a List formatted similar to that shown above. In the MusicExchangeCenter class, add a method called getSong(String title, String ownerName) which returns the Song object with the given title owned by the user with the given ownerName, provided that the user is currently online and that the song exists. Return null otherwise. Hint: you will need to search through the center’s users to find a User with the matching ownerName and then search through that user’s songs to find the Song with the given title. It may be a good idea to write an extra helper method in the User class called songWithTitle(String title) that you can make use of. In the User class, add a downloadSong(MusicExchangeCenter m, String title, String ownerName) method that simulates the downloading of one of the songs in the catalog. It should use the getSong(String title, String ownerName) method that you just wrote, and add the downloaded song to the user’s songList (if not null). Download and execute the MusicExchangeTestProgram2.java file to test your new code. Here is the expected output (note: depending on how you interpreted the instructions, the final songs by Jaw in this test program will have two copies of Bite My Arms Off, which may both be owned by Peter Punk or one may be owned by Peter Punk and the other owned by Disco Stew): COMP 1406 B/C/D – Winter 2023 – Tutorial #6/#7 Due Friday, March 10th, 11:59pm
Mar 13, 2023
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here