Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. 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!
  2. 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.
  3. 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.
  4. 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.
  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!
  6. To ensure you successfully saved all of the data, print out the ArrayLists's size (using .size()) and make sure it is 5100.
  7. 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:
  8. Randomly shuffle your main ArrayList and print the first X songs out (where X is the second command line argument from Step 3)
  9. 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?)
  10. 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... 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

Step: 3

blur-text-image

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

Cost Management Accounting And Control

Authors: Don R. Hansen, Maryanne M. Mowen, Liming Guan

6th Edition

324559674, 978-0324559675

More Books

Students also viewed these Programming questions

Question

Where do you see yourself in 5/10 years?

Answered: 1 week ago