Question
Intro to Java Let's Make a Playlist Background An exciting thing about processing files in Java is that we can now process tons of data
Intro to Java
Let's Make a Playlist
Background
An exciting thing about processing files in Java is that we can now process tons of data all at once. For the rest of the semester, we'll be using files to process large amounts of data. Today will be the first day, where we will create program that generates a playlist of varying length based on user input.
Exercise
For this exercise, we're going to use Billboard's Top 100 songs for each year over 51 years (1965-2015) (source: walkerkq on github). The songs are located in a file stored on Drive: songs.txt. We're going to start with copying the file into our Cloud Editors, and then move on to create playlist generating application.
- Open Lab8.java in your cloud shell. Make sure to use this starter file as there are some new things included that we haven't covered yet!
- Download the songs.txt file from drive by clicking this link. Upload or copy/paste it to Cloud Shell. If you usually copy and paste your files, make sure to copy and paste all of songs.txt! Make sure your songs.txt file is located in the same folder as Lab8.java! Otherwise, your program won't work.
- Our program is going to take in two command line arguments. The first is the name of the file, and the second is the desired length of the playlist. Go ahead and save the filename to a String variable, and parse the second argument into an int.
- Now that we have our command line args saved in the appropriate types, we need to create data structure to hold all of our songs. Let's use an ArrayList of Strings. Once you declare and initialize the ArrayList variable, move on to step 5.
- Use the filename variable that we saved in step 3 to open a new BufferedReader and read the contents of our file into the ArrayList. You should save each line as its own String inside the ArrayList. Check the slides if you aren't sure how to do this step!
- To ensure you successfully saved all of the data, print out the ArrayLists's size (using .size()) and make sure it is 5100.
- Once the ArrayList is full of our data, we need to choose a number of songs out to create the playlist. You can do this multiple ways. Here are some suggestions:
- Randomly shuffle your main ArrayList and print the first X songs out (where X is the second command line argument from Step 3)
- Randomly choose X songs from the list (hint: there's a chance you pick the same song twice. How can we make sure that doesn't happen?)
- Once we are in a position to select songs for the final playlist, choose them and print each out. Number the songs so our user knows we actually gave them the number of songs they asked for!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Welcome to Lab 8 In this lab well be creating a program that generates a playlist of songs based on user input Well be using the Billboard Top 100 son...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started