Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Description CSV is a very simple text-based format that represents tables of data: Every row is on its line Every column value is

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

1 Description CSV is a very simple text-based format that represents tables of data: Every row is on its line Every column value is separated by a comma. For example, the table 1 3410 2 2 3 4 1,2,3,4 3,4,1,0 2,3,4,2 3 4 2 would correspond to the text file containing: In this assignment, your program will need to read a CSV file, parse it to extract the contents, and build a 2D array of type double that will store the data. Then, it needs to some simple math on the 2D array of data, such as compute averages and find min/max values. This 2D array can have an arbitrary number of rows/columns, so do not hard-code any specific dimensions. You are provided with the skeleton of the solution. The class CSVReader has a method readFile() that opens the specified file and returns its contents as one string. So, for above example, readFile would return the string: "1,2,3,4 3,4,1,0 2,3,4,2" You will need to parse this string and extract the data using the split() method of the String: First, split the entire string into "line" tokens, where each token represents a row in the final matrix of data. The number of tokens is the number of rows in the 2D array of doubles. Then, you split each line token to extract individual numeric values. The number of tokens is the number of columns in the 2D array of doubles. At this point, you can allocate your double[][] array. All this functionality will go into the class called DataMatrix, which will contain the 2D array of doubles (as a private instance variable), as well as a method for initializing it based on a single String. Once you have your DataMatrix class initializing 2D array of doubles, you will need to write at least five additional methods for DataMatrix: You can then loop through your tokens and convert each string containing a number - e.g. "1" - into a double value using the static method Double.parse Double(). This double value would then go into your 2D array of doubles at the appropriate location. A method that calculates and returns the average value for every row: public double[] rowAverage(); A method that calculates and returns the average value for every column: public double[] columnAverage(); A method that calculates and returns the overall average value for the data: public double[] matrixAverage(); A method that calculates and returns the minimum value in the data: public double minValue(); A method that calculates and returns the maximum value in the data: public double maxValue(); Make sure the above methods return the data, instead of displaying it. In other words, they must have double as the return type, and contain no print statements. It is also recommended that you implement a method for displaying the 2D array on the screen, so you can compare it to the CSV file and verify that your parser works correctly. How you do this is up to you. 2 Implementation Your assignment will consist of the following three classes: CSVReader - provided by me. Contains the code for a reading date from a file. Don't modify it DataMatrix - must be written by you from scratch. It will implement all of the functionality for your data matrix Assignment2 - a class with the main() method. I provide you with a skeleton that you must expand. The purpose of this class is to test the DataMatrix class and its methods. Your code will have only one main() method, provided in the Assignment2 class. Do not put main methods anywhere else! Assignment2 takes the name of the CSV file as the common line argument. In the main method of Assignment2, you will need to do the following: Load a CSV file into a String. This is already done in the skeleton file provided for you. Create one DataMatrix object and initialize it using the string you've just read in After this, use the appropriate methods of the DataMatrix object to calculate and display: You can assume that the CSV file is correctly formatted and every row has the exact same number of values. 3 Evaluation Your code must compile, run, and have all of the above functionality implemented according to the object-oriented programming (OOP) principles covered in class. Any compiler errors will result in the automatic grade of zero (0) for the assignment. Make sure to have o The average value for every row o The average value for every column o The overall average value for the data o The minimum value in the data o The maximum value in the data Follow submission instruction Correct and nom-missing functionality No Run-time errors No Compiler warnings Good indentation Good variable names Good OOP practices Sufficient comments

Step by Step Solution

3.39 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

Given the detailed description provided here is an example implementation of the three required classes for the CSV file processing assignment 1 CSVRe... 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

College Algebra With Modeling And Visualization

Authors: Gary Rockswold

6th Edition

0134418042, 978-0134418049

More Books

Students also viewed these Programming questions

Question

Divide the expression. X -4 4x

Answered: 1 week ago

Question

Use the binomial theorem to expand each expression. (2 + 3x)

Answered: 1 week ago