Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please add detailed comments above each statement in the following java code. 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

Please add detailed comments above each statement in the following java code.

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; 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; }

class topStreamingArtists{ private Artist first; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

List behaviors to improve effective leadership in meetings

Answered: 1 week ago