Question
I posted this question previously and it was not answered properly. Please insert comments above EACH LINE OF CODE to explain what is taking place.
I posted this question previously and it was not answered properly. Please insert comments above EACH LINE OF CODE to explain what is taking place. Here is the code below.
import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner;
public class ReportPrintDriver { public static void main(String args[] ) throws Exception { TrackData w = new TrackData(); w.readFile(); w.reportArtists(); } } /* * this class represents array structure of data in file in terms of rows and columns */ class TrackData{ int cols; int rows; String[][] data;
//Constructor public TrackData(){ this.cols = 5; this.rows = 10; this.data = new String[rows][cols]; } /* * Read file contents into data array */ public void readFile(){ File text = new File("D:/Chegg/tracks.dat"); Scanner scnr; try { scnr = new Scanner(text); int row =0, col=0; while(scnr.hasNextLine()){ String line = scnr.nextLine(); // System.out.println("" + line); String[] strArr = line.split(","); data[row][col] = strArr[col];col++; data[row][col] = strArr[col];col++; data[row][col] = strArr[col];col++; data[row][col] = strArr[col];col++; data[row][col] = strArr[col];col++; //System.out.println(data[row][2]); col=0;row++; } }catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println("students.dat file not found"); }catch (NumberFormatException e) { // TODO Auto-generated catch block System.out.println("students.dat file has wrong data"); } } /* * create two reports * 1. which artists appear how many times * 2. Top streamed artists */ public void reportArtists(){ PrintWriter writer1 =null; PrintWriter writer2 =null; try { writer1 = new PrintWriter(new FileWriter("D:/Chegg/artists.dat")); writer2 = new PrintWriter(new FileWriter("D:/Chegg/TopStramedArtists.dat")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println(" file not found"); } catch (IOException e) { // TODO Auto-generated catch block System.out.println(" file is not accesible"); } String[] artistsArr = new String[rows]; int[] count = new int[rows]; int[] streamCount = new int[rows]; int index = 0; int atWhichIndex=-1; for(int i=0;i class Artist{ String name; Artist next; //Makes it a linked-list } class topStreamingArtists{ private Artist first; //Cannot be accessed outside the class }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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