Question

In: Computer Science

Leave code as is ALL I NEED IS TO MAKE THE LIST INTO ASCENDING ORDER FROM...

Leave code as is ALL I NEED IS TO MAKE THE LIST INTO ASCENDING ORDER FROM A TO Z OF ARTISTS NAMES

YOU CAN USE THIS AS REFERENCE SPOTIFY LIST TOP 50 AS REFERENCE FOR CSV FILE https://spotifycharts.com/viral/

import java.io.*;


public class Spotify
{
    public static void main(String[]args) {

        // Read csv Spotify file located on my desktop
        // Download csv file, save on desktop, and add file location in csvFile = " "
        String csvFile = "CSVFILE LOCATION OF TOP ARTISTS HERE";



        String line = "";

            // Try catch block when reading and opening files
            try {
                BufferedReader br = new BufferedReader(new FileReader(csvFile));
                // Create text file
                File theFile = new File("Artists-Week-Of-09-01-2020.txt");
                PrintStream out = new PrintStream(new FileOutputStream(theFile));
                // While next line is not null parse the line with commas and store it into
                // values array
                while ((line = br.readLine()) != null) {
                    String[] values = line.split(",");
                    // Print artists name located in [2] to console
                    System.out.println(values[2]);
                    // Print artists name to text file report
                    out.print(values[2] + "\n");
                }
                        // Close PrintStream
                       out.close();
                } catch(FileNotFoundException e){
                    e.printStackTrace();
                }   catch(IOException e){
                    e.printStackTrace();
                }
            
    }
}

Solutions

Expert Solution

In the spotify class declaraed the list variable .In the list variable adding the all the artist names and sorting that using the Collection.sort method.it will sort the values into the ascending order.Please find the below code to print the ascending order of the artistname.

In the code for the csvFile variable include the path of your csv file.

Please find the below code.

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Spotify {
   public static void main(String[] args) {

       // Read csv Spotify file located on my desktop
       // Download csv file, save on desktop, and add file location in csvFile = " "
       String csvFile = "YOUR CSV FILE LOCATION";

       String line = "";
       // created one list to add the all the artist name's of csv file
       List<String> artistList = new ArrayList<String>();
       // Try catch block when reading and opening files
       try {
           BufferedReader br = new BufferedReader(new FileReader(csvFile));
           // Create text file
           File theFile = new File("Artists-Week-Of-09-01-2020.txt");
           PrintStream out = new PrintStream(new FileOutputStream(theFile));
           // While next line is not null parse the line with commas and store it into
           // values array
           while ((line = br.readLine()) != null) {
               String[] values = line.split(",");
               // Print artists name located in [2] to console

               // adding artist name into the list
               // trim method to remove the any white spaces in the starting or ending of the
               // name.
               artistList.add(values[2].trim());

           }
           // adding Collections.sort it will do ascending order of the elements
           Collections.sort(artistList);
           // iterating over the list
           for (String artistName : artistList) {
               // printing sorted artist names into the file
               out.print(artistName + "\n");
               // printing into the console
               System.out.println(artistName);
           }
           // Close PrintStream
           out.close();
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }

   }
}

input :

Below one is the input screenshort of csv file.

Output:

This is the artistnames with ascending order.

Summary:

Added on list variable included all the artistnames then sorted using the Collections.sort method.After sorting the names then printed into the file.


Related Solutions

Explain the ascending process of the spinothalamic tract from when the fibers leave the DRG. Make...
Explain the ascending process of the spinothalamic tract from when the fibers leave the DRG. Make sure to include 1st, 2nd and 3rd order neurons and point of decussation.
Hi there, I need mpx2100ap arduino code do I need an amplifier to make this work...
Hi there, I need mpx2100ap arduino code do I need an amplifier to make this work ?
Before you leave for the weekend, could you make a list of all the possible risks...
Before you leave for the weekend, could you make a list of all the possible risks for this service department system project? I'd like to think about our risks over the weekend and discuss with you on Monday.
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c...
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c program, you should end up with a simple English-French and French-English dictionary with a couple of about 350 words(I've provided 5 of each don't worry about this part). I just need a way to look up a word in a sorted array. You simply need to find a way to identify at which index i a certain word appears in an array of words...
list in ascending order the levels of hierarchy of complexity. define each level and provide an...
list in ascending order the levels of hierarchy of complexity. define each level and provide an example for each.
I need a step by step explanation to the following problem in order to make me...
I need a step by step explanation to the following problem in order to make me understand the solution: 14-23 Flexible Budgets and Operating-Income Variance Analysis: Spreadsheet Application The following information is available for Brownstone Products Company for the month of July: Actual Master Budget Units                       3,800                         4,000 Sales Revenue                     53,200                      60,000 Variable manufacturing costs                     19,000 16,000 Fixed manufacturing costs                     16,000                      15,000 Variable selling and administrative expenses                       7,700                         8,000 Fixed selling...
code in python I want to make a function that adds all the multipliers together. The...
code in python I want to make a function that adds all the multipliers together. The code is posted below and please look at wanted output section to see what I want the code to output. The last line of the code is the only addition I need. Thanks. Code: initial=int(input("Initial value : "))       #taking inputs multiplier=float(input("Multiplier : ")) compound=int(input("No of compounds : ")) print("Your values are:") mult=initial                         #initalizing to find answer for i in range(0,compound):         #multiplying by multiplier    ...
These are a list of the transactions I have from playing Monopoly. I need to create...
These are a list of the transactions I have from playing Monopoly. I need to create a balance sheet, income statement, and cash flow. STOCK- Issued $1500 common stock LAND/STOCK- $600 issued for purchase of Land 1 RENT REVENUE- $16.00 From New York Ave 2 CONSULTING REV(ACCTS REC.) - Collected $200 for passing Go 3 LAND - Purchase Kentucky Ave $220.00 4 RENT EXPENSE - $200.00 for landing on Railroad 5 CONSULTING REV(ACCTS REC.) - Collected $200 for passing Go...
I NEED A LIST OF ALL OF THE CONSTRAINTS Case 1 Description - Planning an Advertising...
I NEED A LIST OF ALL OF THE CONSTRAINTS Case 1 Description - Planning an Advertising Campaign The Flamingo Grill is an upscale restaurant located in St. Petersburg, Florida. To help plan an advertising campaign for the coming season, Flamingo's management team hired the advertising firm of Haskell & Johnson (HJ). The management team requested HJ's recommendation concerning how the advertising budget should be distributed across television, radio, and newspaper advertisements. The budget has been set at $279,000. In a...
Hello i need someone to implement in JAVA a radix sort algorithm forsorting strings in ascending...
Hello i need someone to implement in JAVA a radix sort algorithm forsorting strings in ascending order. The input to your algorithm should be a (multi)set S = [S1, S2, . . . , Sn] of strings each of which is of length m over the English alphabet [A…Z, a…z]. The output should be the set sorted in ascending lexicographical order. Number of strings is >= 100 and number of characters >= 50 i need the answer fast please
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT