CMSC 203, Assignment 5 Spring 2018 Concepts Utilized in this Project Creating cl
ID: 3704096 • Letter: C
Question
CMSC 203, Assignment 5
Spring 2018
Concepts Utilized in this Project
Creating classes based on Javadoc
Two Dimensional Arrays
Passing two dimensional arrays to and from methods
Creating a Utility class (static methods)
JUnit testing
Reading from a file
Writing to a file
Using methods of the utility class within an existing GUI driver class
Must follow Javadoc to implement correctly
Overview
When GUI application starts (provided), user is shown display of Store Names and Item Names
User selects Load Sales Data to select the file containing the sales data. The application then displays the sales for each store and each item as well as the totals for the store and the totals for the item. The store with the highest sales for each item will be highlighted.
Exit will exit the application.
Specifications & Requirements
Create a utility class that manipulates a two-dimensional ragged array of doubles. It will accommodate positive and negative numbers. Follow the Javadoc provided.
This utility class will be used with an existing GUI class to create a sales report.
Testing of the utility class will be done with the JUnit tests and the GUI class provided for you.
Utility class
The class TwoDimRaggedArrayUtility will follow the provided Javadoc and will contain the following methods:
Method readFile – pass in a file and return a two-dimensional ragged array of doubles
Method writeToFile – pass in a two-dimensional ragged array of doubles and a file, and writes the ragged array into the file. Each row is on a separate line and each double is separated by a space.
Method getTotal – pass in a two-dimensional ragged array of doubles and returns the total of the elements in the array.
Method getAverage – pass in a two-dimensional ragged array of doubles and returns the average of the elements in the array (total/num of elements).
Method getRowTotal – pass in a two-dimensional ragged array of doubles and a row index and returns the total of that row. Row index 0 is the first row in the array.
Method getColumnTotal - pass in a two-dimensional ragged array of doubles and a column index and returns the total of that column. Column index 0 is the first column in the array. If a row doesn’t contain that column, it is not an error, that row will not participate in this method.
Method getHighestInRow - pass in a two-dimensional ragged array of doubles and a row index and returns the largest element in that row. Row index 0 is the first row in the array.
Method getLowestInRow - a two-dimensional ragged array of doubles and a row index and returns the smallest element in that row. Row index 0 is the first row in the array.
Method getHighestInColumn - pass in a two-dimensional ragged array of doubles and a column index and returns the largest element in that column. Column index 0 is the first column in the array. If a row doesn’t contain that column, it is not an error, that row will not participate in this method.
Method getLowestInColumn - pass in a two-dimensional ragged array of doubles and a column index and returns the smallest element in that column. Column index 0 is the first column in the array. If a row doesn’t contain that column, it is not an error, that row will not participate in this method.
Method getHighestInArray - pass in a two-dimensional ragged array of doubles and returns the largest element in the array.
Method getLowestInArray - pass in a two-dimensional ragged array of doubles and returns the smallest element in the array.
GUI Application – provided for you
1.Uses methods of TwoDimRaggedArrayUtility
2.When the Load Sales Data button is selected the sales data is read from a file and displayed on the screen with the sales data as well as the totals for each store and the totals for each item. The largest sales for each item is highlighted.
3.The file contains a row for each store and each double in the row is separated by a space
4. must provide two additional input files and a screenshot of the results of each. Each file will have 6 rows and up to 6 numbers on each row. They must represent ragged arrays.
JUnit Test
1.Contains test for each of the methods of TwoDimRaggedArrayUtility
2. will fill in values for a new dataset – called dataSetSTUDENT
3. will implement the STUDENT test files using the dataSetSTUDENT.
This sample output
Class TwoDimRaggedArrayUtility
extends java.lang.Object
This utility works with 2 dimensional ragged arrays with a maximum of 10 rows and 10 columns
This utility works with negative and positive numbers
This is a utility class - there are no private data members
Author:
Jeannette Kartchner
TwoDimRaggedArrayUtility
readFile
Reads from a file and returns a ragged array of doubles The maximum rows is 10 and the maximum columns for each row is 10 Each row in the file is separated by a new line Each element in the row is separated by a space Suggestion: You need to know how many rows and how many columns there are for each row to create a ragged array. 1. Read the doubles from the file into an a temporary array [10][10] of Strings which was initialized to nulls. 2. Find out how many rows there are (any row that has the first element != null is a valid row) 3. Create the array based on the num of rows, i.e. double[][]array = new double[#rows][] 4. Determine the number of columns for the first row (any element != null is a valid element) 5. Create the first row, i.e. array[0] = new double[#columns] 6. Put the values from the temporary array into in the row (don't forget to convert from strings to doubles) 7. Repeat for all rows
Parameters:
file - the file to read from
Returns:
a two dimensional ragged (depending on data) array of doubles if the file is not empty, returns a null if file is empty
Throws:
java.io.FileNotFoundException
writeToFile
Writes the ragged array of doubles into the file. Each row is on a separate line within the file and each double is separated by a space.
Parameters:
data - two dimensional ragged array of doubles
outputFile - the file to write to
Throws:
java.io.FileNotFoundException - if outputFile is not valid
getTotal
Returns the total of all the elements of the two dimensional array
Parameters:
data - the two dimensional array getting total of
Returns:
the sum of all the elements in the two dimensional array
getAverage
Returns the average of the elements in the two dimensional array
Parameters:
data - the two dimensional array getting the average of
Returns:
the average of the elements in the two dimensional array (total of elements/num of elements)
getRowTotal
Returns the total of the selected row in the two dimensional array index 0 refers to the first row.
Parameters:
data - the two dimensional array
row - the row index to take the total of (0 refers to the first row)
Returns:
the total of the row
getColumnTotal
Returns the total of the selected column in the two dimensional array index 0 refers to the first column. If a row in the two dimensional array doesn't have this column index, it is not an error, it doesn't participate in this method.
Parameters:
data - the two dimensional array
col - the column index to take the total of (0 refers to the first column)
Returns:
the total of the column
getHighestInRow
Returns the largest element of the selected row in the two dimensional array index 0 refers to the first row.
Parameters:
data - the two dimensional array
row - the row index to find the largest element of (0 refers to the first row)
Returns:
the largest element of the row
getLowestInRow
Returns the smallest element of the selected row in the two dimensional array index 0 refers to the first row.
Parameters:
data - the two dimensional array
row - the row index to find the smallest element of (0 refers to the first row)
Returns:
the smallest element of the row
getHighestInColumn
Returns the largest element of the selected column in the two dimensional array index 0 refers to the first column. If a row in the two dimensional array doesn't have this column index, it is not an error, it doesn't participate in this method.
Parameters:
data - the two dimensional array
col - the column index to find the largest element of (0 refers to the first column)
Returns:
the largest element of the column
getLowestInColumn
Returns the smallest element of the selected column in the two dimensional array index 0 refers to the first column. If a row in the two dimensional array doesn't have this column index, it is not an error, it doesn't participate in this method.
Parameters:
data - the two dimensional array
col - the column index to find the smallest element of (0 refers to the first column)
Returns:
the smallest element of the column
getHighestInArray
Returns the largest element in the two dimensional array
Parameters:
data - the two dimensional array
Returns:
the largest element in the two dimensional array
getLowestInArray
Returns the smallest element in the two dimensional array
Parameters:
data - the two dimensional array
Returns:
the smallest element in the two dimensional array
...............................
....................................
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Constructor Summary TwoDimRaggedArrayUtility()CMSC 203, Assgmmt S Spring 2018 .Creating classes based on Javadoc Passing two dimensional arays so and from methods Creating a Ublity class (stanic methods) JUnit bestong Reading from a file Wieiting to a file Using methods of the utility class within an existing GUT driver class * o Must folew avadec to implesent coreectly User selects Load Sales Data to select the file coetaining the sales data The application then displays the sales for each store and each es as well an the totals for the stoce and the totals for dhe item The store with the highest sales for each item wil be highlighed irwill eit the application Crease ality class at manipulanes a twe dimeeniosal raggnd aay of doubles It will ccommodate This ulity elass wll be used wh an existing GU1 class reate a sales report Tesing of the utlay class will be done wih the itand the GUT class provided for you Ceiliey clans The clas wl follow the provided Jad and will contain the following Method geade-pass in a file and setan a two-dimsional ragend array of doubles Mehod getTetal pass in a two dimsional ragged away of doubles and renarm tdhe total of de Method tAerage-pas in a two-dional agged away of doubles and seturns the avwage of the
Explanation / Answer
Hi, Please find the comments in line. Specifically getAverage method. Please rate the answer.