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.
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...
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT