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.
Without dramatically changing the code please add a basic "linked list in ascending order" (option 7)....
Without dramatically changing the code please add a basic "linked list in ascending order" (option 7). Please leave comments within the code so I can understand what is being done, thank you. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node link; public Node() { link = null; data = 0; } public Node(int d,Node n) { data = d; link = n; } public void setLink(Node n) { link = n; } public void...
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.
I need to make changes to code following the steps below. The code that needs to...
I need to make changes to code following the steps below. The code that needs to be modified is below the steps. Thank you. 1. Refactor Base Weapon class: a.            Remove the Weapon abstract class and create a new Interface class named WeaponInterface. b.            Add a public method fireWeapon() that returns void and takes no arguments. c.             Add a public method fireWeapon() that returns void and takes a power argument as an integer type. d.            Add a public method activate()...
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 ?
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.
***C++ Coding*** Write a program for sorting a list of integers in ascending order using the...
***C++ Coding*** Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Please include comments to understand code. Requirements Implement the following functions: int readData( int **arr) arr is a pointer to pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array arr. The first integer number in the file is the number of intergers....
C++ Write a program for sorting a list of integers in ascending order using the bubble...
C++ Write a program for sorting a list of integers in ascending order using the bubble sort algorithm Requirements Implement the following functions: Implement a function called readData int readData( int **arr) arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array arr. The first integer number in the file is the number of intergers. After the first number,...
I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT