Question: I have to create a Utility class based upon these instructions and I need help with it: The class TwoDimRaggedArrayUtility w ill follow the provided

I have to create a Utility class based upon these instructions and I need help with it:

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 *** this is where I'm stuck as I'm having an issue with reading and loading the file **

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 doesnt 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 doesnt 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 doesnt 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

Uses methods of TwoDimRaggedArrayUtility

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.

The file contains a row for each store and each double in the row is separated by a space

Student 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.

=====================================The provided code and .txt file===========================

MyGuiFx

/** * MvGuiFx, Class representing the GUI for Displaying a DisneyWorld District 5 Sales Report */ import java.io.File; import java.io.FileNotFoundException; import java.text.NumberFormat; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.HPos; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.Tooltip; import javafx.stage.FileChooser; import javafx.stage.Stage; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Font; public class MyGuiFx extends Application {; private double[][] sales; public static final int MAX_STORES = 6; public static final int MAX_ITEMS = 6; private NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); Button readFileBtn, exitBtn, copyFileBtn; GridPane dataPane; /** * Lets the user choose a file to read the sales information and displays * the information on the screen * @throws FileNotFoundException */ public void readFile() throws FileNotFoundException { File selectedFile; FileChooser chooser = new FileChooser(); chooser.setTitle("Choose a file to read retail items' sales information"); if ((selectedFile = chooser.showOpenDialog(null)) != null) { // Read the file sales = TwoDimRaggedArrayUtility.readFile(selectedFile); } //clear table clearTable(); //display on the screen int row,col; double total; for(row=0;row columns) columns = sales[row].length; //display column totals for(col=0;col 
//TwoRimmedRaggedArrayUtilityTest 

import static org.junit.Assert.*;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.PrintWriter;

import java.util.Scanner;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

public class TwoDimRaggedArrayUtilityTest {

private double[][] dataSet1 = {{1,2,3},{4,5},{6,7,8}};

private double[][] dataSet2 = {{7,2,9,4},{5},{8,1,3},{11,6,7,2}};

private double[][] dataSet3 = {{7.2,2.5,9.3,4.8},{5.9},{8.1,1.7,3.3},{11.6,6.9,7.3,2.7}};

private double[][] dataSet4 = {{-2.5,-5.3,6.1},{-4.4,8.2},{2.3,-7.5},{-4.2,7.3,-5.9,2.6}};

//STUDENT fill in dataSetSTUDENT with values, it must be a ragged array

private double[][] dataSetSTUDENT;

private File inputFile,outputFile;

@Before

public void setUp() throws Exception {

outputFile = new File("TestOut.txt");

}

@After

public void tearDown() throws Exception {

dataSet1 = dataSet2 = dataSet3 = dataSet4 = dataSetSTUDENT = null;

inputFile = outputFile = null;

}

/**

* Test getTotal method

* Returns the total of all the elements in the two dimensional array

*/

@Test

public void testGetTotal() {

assertEquals(36.0,TwoDimRaggedArrayUtility.getTotal(dataSet1),.001);

assertEquals(65.0,TwoDimRaggedArrayUtility.getTotal(dataSet2),.001);

assertEquals(71.3,TwoDimRaggedArrayUtility.getTotal(dataSet3),.001);

assertEquals(-3.3,TwoDimRaggedArrayUtility.getTotal(dataSet4),.001);

}

/**

* Test getAverage method

* Returns the average of all the elements in the two dimensional array

*/

@Test

public void testGetAverage() {

assertEquals(4.5,TwoDimRaggedArrayUtility.getAverage(dataSet1),.001);

assertEquals(5.417,TwoDimRaggedArrayUtility.getAverage(dataSet2),.001);

assertEquals(5.942,TwoDimRaggedArrayUtility.getAverage(dataSet3),.001);

assertEquals(-.3,TwoDimRaggedArrayUtility.getAverage(dataSet4),.001);

//fail("Not yet implemented");

}

/**

* Student test for getAverage method

* Use the dataSetSTUDENT

* Returns the average of all the elements in the two dimensional array

*/

@Test

public void testGetAverageSTUDENT() {

fail("Not yet implemented");

}

/**

* Test getRowTotal method

* Returns the total of all the elements of the row.

* Row 0 refers to the first row in the two dimensional array

*/

@Test

public void testGetRowTotal() {

assertEquals(9.0,TwoDimRaggedArrayUtility.getRowTotal(dataSet1,1),.001);

assertEquals(5.0,TwoDimRaggedArrayUtility.getRowTotal(dataSet2,1),.001);

assertEquals(22.0,TwoDimRaggedArrayUtility.getRowTotal(dataSet2,0),.001);

assertEquals(28.5,TwoDimRaggedArrayUtility.getRowTotal(dataSet3,3),.001);

assertEquals(5.9,TwoDimRaggedArrayUtility.getRowTotal(dataSet3,1),.001);

assertEquals(3.8,TwoDimRaggedArrayUtility.getRowTotal(dataSet4,1),.001);

assertEquals(-.2,TwoDimRaggedArrayUtility.getRowTotal(dataSet4,3),.001);

//fail("Not yet implemented");

}

/**

* StudenttTest for getRowTotal method

* Use the dataSetSTUDENT

* Returns the total of all the elements of the row.

* Row 0 refers to the first row in the two dimensional array

*/

@Test

public void testGetRowTotalSTUDENT() {

fail("Not yet implemented");

}

/**

* Test getColumnTotal method

* Returns the total of all the elements in the 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.

* Column 0 refers to the first column in the two dimensional array

*/

@Test

public void testGetColumnTotal() {

assertEquals(11.0,TwoDimRaggedArrayUtility.getColumnTotal(dataSet1,0),.001);

assertEquals(19.0,TwoDimRaggedArrayUtility.getColumnTotal(dataSet2,2),.001);

assertEquals(11.1,TwoDimRaggedArrayUtility.getColumnTotal(dataSet3,1),.001);

assertEquals(-8.8,TwoDimRaggedArrayUtility.getColumnTotal(dataSet4,0),.001);

assertEquals(2.7,TwoDimRaggedArrayUtility.getColumnTotal(dataSet4,1),.001);

//fail("Not yet implemented");

}

/**

* Student test for the getColumnTotal method

* Use dataSetSTUDENT

* Returns the total of all the elements in the 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.

* Column 0 refers to the first column in the two dimensional array

*/

@Test

public void testGetColumnTotalSTUDENT() {

fail("Not yet implemented");

}

/**

* Test getHighestInRow method

* Returns the largest of all the elements in the row.

* Row 0 refers to the first row in the two dimensional array

*/

@Test

public void testGetHighestInRow() {

assertEquals(3.0,TwoDimRaggedArrayUtility.getHighestInRow(dataSet1,0),.001);

assertEquals(8.0,TwoDimRaggedArrayUtility.getHighestInRow(dataSet2,2),.001);

assertEquals(5.9,TwoDimRaggedArrayUtility.getHighestInRow(dataSet3,1),.001);

assertEquals(6.1,TwoDimRaggedArrayUtility.getHighestInRow(dataSet4,0),.001);

assertEquals(8.2,TwoDimRaggedArrayUtility.getHighestInRow(dataSet4,1),.001);

//fail("Not yet implemented");

}

/**

* Test getLowestInRow method

* Returns the smallest of all the elements in the row.

* Row 0 refers to the first row in the two dimensional array

*/

@Test

public void testGetLowestInRow() {

assertEquals(6.0,TwoDimRaggedArrayUtility.getLowestInRow(dataSet1,2),.001);

assertEquals(5.0,TwoDimRaggedArrayUtility.getLowestInRow(dataSet2,1),.001);

assertEquals(2.5,TwoDimRaggedArrayUtility.getLowestInRow(dataSet3,0),.001);

assertEquals(-4.4,TwoDimRaggedArrayUtility.getLowestInRow(dataSet4,1),.001);

assertEquals(-7.5,TwoDimRaggedArrayUtility.getLowestInRow(dataSet4,2),.001);

//fail("Not yet implemented");

}

/**

* Test getHighestInColumn method

* Returns the largest of all the elements in the 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.

* Column 0 refers to the first column in the two dimensional array

*/

@Test

public void testGetHighestInColumn() {

assertEquals(8.0,TwoDimRaggedArrayUtility.getHighestInColumn(dataSet1,2),.001);

assertEquals(6.0,TwoDimRaggedArrayUtility.getHighestInColumn(dataSet2,1),.001);

assertEquals(11.6,TwoDimRaggedArrayUtility.getHighestInColumn(dataSet3,0),.001);

assertEquals(8.2,TwoDimRaggedArrayUtility.getHighestInColumn(dataSet4,1),.001);

assertEquals(6.1,TwoDimRaggedArrayUtility.getHighestInColumn(dataSet4,2),.001);

//fail("Not yet implemented");

}

/**

* Test getLowestInColumn method

* Returns the smallest of all the elements in the 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.

* Column 0 refers to the first column in the two dimensional array

*/

@Test

public void testGetLowestInColumn() {

assertEquals(2.0,TwoDimRaggedArrayUtility.getLowestInColumn(dataSet1,1),.001);

assertEquals(3.0,TwoDimRaggedArrayUtility.getLowestInColumn(dataSet2,2),.001);

assertEquals(5.9,TwoDimRaggedArrayUtility.getLowestInColumn(dataSet3,0),.001);

assertEquals(-4.4,TwoDimRaggedArrayUtility.getLowestInColumn(dataSet4,0),.001);

assertEquals(-7.5,TwoDimRaggedArrayUtility.getLowestInColumn(dataSet4,1),.001);

//fail("Not yet implemented");

}

/**

* Test getHighestInArray method

* Returns the largest of all the elements in the two dimensional array.

*/

@Test

public void testGetHighestInArray() {

assertEquals(8.0,TwoDimRaggedArrayUtility.getHighestInArray(dataSet1),.001);

assertEquals(11.0,TwoDimRaggedArrayUtility.getHighestInArray(dataSet2),.001);

assertEquals(11.6,TwoDimRaggedArrayUtility.getHighestInArray(dataSet3),.001);

assertEquals(8.2,TwoDimRaggedArrayUtility.getHighestInArray(dataSet4),.001);

//fail("Not yet implemented");

}

/**

* Student test for the getHighestInArray method

* Use the dataSetSTUDENT

* Returns the largest of all the elements in the two dimensional array.

*/

@Test

public void testGetHighestInArraySTUDENT() {

fail("Not yet implemented");

}

/**

* Test getLowestInArray method

* Returns the smallest of all the elements in the two dimensional array.

*/

@Test

public void testGetLowestInArray() {

assertEquals(1.0,TwoDimRaggedArrayUtility.getLowestInArray(dataSet1),.001);

assertEquals(1.0,TwoDimRaggedArrayUtility.getLowestInArray(dataSet2),.001);

assertEquals(1.7,TwoDimRaggedArrayUtility.getLowestInArray(dataSet3),.001);

assertEquals(-7.5,TwoDimRaggedArrayUtility.getLowestInArray(dataSet4),.001);

//fail("Not yet implemented");

}

/**

* Test the writeToFile method

* write the array to the outputFile File

* then read it back to make sure formatted correctly to read

*

*/

@Test

public void testWriteToFile() {

double[][] array=null;

try {

TwoDimRaggedArrayUtility.writeToFile(dataSet4, outputFile);

} catch (Exception e) {

fail("This should not have caused an Exception");

}

//now read from the output file

try {

array = TwoDimRaggedArrayUtility.readFile(outputFile);

assertEquals(-2.5, array[0][0],.001);

assertEquals(-5.3, array[0][1],.001);

assertEquals(6.1, array[0][2],.001);

assertEquals(-4.4, array[1][0],.001);

assertEquals(8.2, array[1][1],.001);

assertEquals(2.3, array[2][0],.001);

assertEquals(-7.5, array[2][1],.001);

assertEquals(-4.2, array[3][0],.001);

assertEquals(7.3, array[3][1],.001);

assertEquals(-5.9, array[3][2],.001);

assertEquals(2.6, array[3][3],.001);

} catch (FileNotFoundException e) {

fail("This should not have caused an Exception");

}

}

/**

* Test the readFile method

* reads from a file and then test that the returned two dimensional array of doubles

* is ragged.

*/

@Test

public void testReadFile() {

double[][] array=null;

try {

inputFile = new File("Test1.txt");

PrintWriter inFile = new PrintWriter(inputFile);

inFile.print("-2.5 -5.3 6.1 " +

"-4.4 8.2 " +

"2.3 -7.5 " +

"-4.2 7.3 -5.9 2.6");

inFile.close();

array = TwoDimRaggedArrayUtility.readFile(inputFile);

assertEquals(-2.5, array[0][0],.001);

assertEquals(-5.3, array[0][1],.001);

assertEquals(6.1, array[0][2],.001);

assertEquals(-4.4, array[1][0],.001);

assertEquals(8.2, array[1][1],.001);

assertEquals(2.3, array[2][0],.001);

assertEquals(-7.5, array[2][1],.001);

assertEquals(-4.2, array[3][0],.001);

assertEquals(7.3, array[3][1],.001);

assertEquals(-5.9, array[3][2],.001);

assertEquals(2.6, array[3][3],.001);

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

fail("This should not have caused an FileNotFoundException");

}

//testing that the array is a ragged array

try{

assertEquals(0.0, array[1][2],.001);

fail("This should have caused a ArrayIndexOutOfBoundsException");

} catch (ArrayIndexOutOfBoundsException e){

assertTrue("Correctly threw ArrayIndexOutOfBoundsException", true);

}

catch (Exception e) {

// TODO Auto-generated catch block

fail("This should not have caused an Exception");

}

//testing that the array is a ragged array

try{

assertEquals(0.0, array[2][2],.001);

fail("This should have caused a ArrayIndexOutOfBoundsException");

} catch (ArrayIndexOutOfBoundsException e){

assertTrue("Correctly threw ArrayIndexOutOfBoundsException", true);

}

catch (Exception e) {

// TODO Auto-generated catch block

fail("This should not have caused an Exception");

}

}

}

DATA FILE

district5.txt 
1253.65 4566.50 2154.36 7532.45 3388.44 6598.23 2876.22 3576.24 1954.66 4896.23 2855.29 2386.36 5499.29 2256.76 3623.76 4286.29 5438.48 3794.43 3184.38 3654.65 3455.76 6387.23 4265.77 4592.45 2657.46 3265.34 2256.38 8935.26 5287.34 
;col++)>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!