Rap 1 Рop 2 Classical 0 Hip Hop 2 Rock 2 Lo Fi 0 c. The returned array should contain the follow Croato a puhlic ctatic mothod namnd nlaul mothod nam ed
Java Code
Problem Description
Every year, music streaming platforms release a summary of a user’s listening statistics throughout the
year. As a result, many other websites have emerged evaluating different aspects of listening habits.
Your job is to create a program that creates and evaluates the genres of the songs within the playlist and
decide how often they will be listened to based on their popularity. This assignment will test your basic
knowledge of Scanner, static methods, and arrays.
Notes:
• You must reuse code when possible. Look for hints suggesting code reuse.
• Only create ONE Scanner object (when prompted in the main method) and reuse it whenever you need to
read more input. Creation/use of more than one Scanner may result in a zero for the assignment!
Solution Description
1. Create a class named Playlist
2. Create a public static method named addPlaylistInfo that takes in a Scanner object and does not
return anything. Prompts should be on the same line as user input. Each unique prompt should be printed
on separate lines. Within this method:
a. Print to the console “Enter number of songs in playlist: ”
b. Read the user’s input as an int and assign it to an int named numSongs
c. Print to the console “Enter a playlist name: ”
d. Read the user’s input as a String and assign it to a String named playlistName. The
playlist name may contain spaces, so the entire line of user input should be read in.
e. Print the name and number of songs in the following format:
Playlist created successfully. Here are the details:
Number of Songs: {numSongs}
Name: {playlistName}
3. Create a public static method named genreTally that takes in the following two parameters: a
String[] named genreArray, which represents the actual genres found within a playlist, and
another String[] named genres, which represents all possible genres that can be found within a
playlist. This method should return an int[] that represents the tally of each genre present within the
playlist. Within this method:
a. Print the following statement once: “The following types of genres are in
your playlist:”
b. For each String in genres, loop through the genreArray and keep a tally of how many
songs of each genre exists within genreArray. Then, print out a new line with the genre and
the total number of that type of genre.
i. HINT: Make sure that this method works for any size genreArray it receives
ii. For example, if genreArray contains [“Rap”, “Rock”, “Rock”, “Pop”,
“Pop”, “Hip Hop”, “Hip Hop”] and genres contains [“Rap”, “Pop”,
“Classical”, “Hip Hop”, “Rock”, “Lo Fi”] you should print out:
Rap 1
Pop 2
Classical 0
Hip Hop 2
Rock 2
Lo Fi 0
c. The returned array should contain the following values: [1, 2, 0, 2, 3, 0]
4. Create a public, static method named playlistScores that takes in three String[] parameters
named playlist1, playlist2, and genres in that order. This method should return nothing.
Within this method:
a. Calculate the popularity of each playlist array. To calculate the popularity of a playlist array, take
the sum of each element within the array multiplied by its index.
i. HINT: You already have a method that calculates the amount of each genre found within
a playlist. You must use that method when calculating playlist popularity.
ii. For example, the “score” of this playlist: [“Rap”, “Rap”, “Rap”, “Rap”,
“Rap”, “Pop”] using the genres array of
[“Rap”, “Pop”, “Classical”, “Hip Hop”, “Rock”, “Lo Fi”]
would be 1 because there are 5 “Rap” songs
The rest is in the image.
![Rap 1
Pop 2
Classical 0
Нip Hop 2
Rock 2
Lo Fi 0
The returned array should contain the following values: [1, 2, 0, 2, 3, 0]
c.
4.
Create a public, static method named playlistScores that takes in three String[] parameters
named playlist1,playlist2, and genres in that order. This method should return nothing.
Within this method:
a.
Calculate the popularity of each playlist array. To calculate the popularity of a playlist array, take
the sum of each element within the array multiplied by its index.
i. HINT: You already have a method that calculates the amount of each genre found within
a playlist. You must use that method when calculating playlist popularity.
ii. For example, the "score" of this playlist: ["Rap", "Rap", "Rap", "Rap",
"Rap", "Pop"] using the genres array of
["Rap", "Pop", "Classical", "Hip Hop", "Rock", "Lo Fi"]
would be 1 because there are 5 "Rap" songs which are located at index 0 in genres
and there is 1 "Pop" song which is located at index 1 in genres. 5*0+ 1*1 = 1.
b. If playlistl's score is greater than playlist2's score, print "The first playlist
is likely to have more listeners than the second."
c. If playlist2's score is greater than playlistl's score, print "The second playlist
is likely to have more listeners than the first."
d.
If the two scores are equal, print "The two playlists are predicted to perform
equally well."
5.
Create a main method.
Create a String [] named genres with the following values: "Rap", "Pop",
"Classical", "Hip Hop", "Rock", and "Lo Fi".
Declare two String[] variables named playlistl and playlist2, respectively.
а.
b.
i.
These arrays should have a length of 7 and be filled with random values from the
genres array you already declared.
Note: you don't have to use Math.random ( ), you can pick whatever values you want.
i.
с.
Create a Scanner object named scan.
REMINDER: This is the ONLY instance of Scanner you should create!
d.
Print the numbers of songs on each playlist and give it a name. This information should be input
from the user.
HINT: you have already created the method that does this.
Print out the "Tally" of genres found within each playlist.
е.
HINT: you have already created the method that does this.
f. Compare the popularity of the playlists to see which one is likely to have more listeners.
HINT: you have already created the method that does this.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8a1ff5b0-6d62-4156-84f4-ecc9607dcad9%2F2714e3ca-8d04-4af9-b30c-9e854421cefe%2F1a0134s_processed.jpeg&w=3840&q=75)


Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









