Say that you are designing software to handle tables of data (like a spreadsheet
ID: 3595845 • Letter: S
Question
Say that you are designing software to handle tables of data (like a spreadsheet or statistical analysis software) and want to create a table of data object (like a matrix or a data frame) which supports the following functionality: • populate the table from a .csv file • retrieve the number of rows from this table • retrieve the number of columns from this table • retrieve a specific row of the table, returned as an array • retrieve a specific column of the table, returned as an array • retrieve all the data, returned as a two dimensional array • change a value at a specific row and specific column to a given new value Write a Java interface to design this object, where the data type in the table is specified by a generic parameter (if you cannot figure out generics, assume all data values will be of type double for reduced credit). Note that interfaces do not define constructors. DO NOT implement the interface with an abstract or implementing class, only create the interface class. You must decide on effective and practical names, parameters, and return types
Explanation / Answer
Implemeted interface as per the requirement, clearly added comments for better readability. Now you can use this interface to design the application
code:
-----------------
interface DataHandle<T>{
//Taking file input file name, table name. This function returns success upon successful population of data into the table
boolean populateTable(File input_fil_name, String table_name);
//This function takes table name as parameter and returns the number of rows in the table
int countRows(String table_name);
//This function takes table name as parameter and returns the number of columns in the table
int countColumns(String table_name);
//This function takes table name and index at which data needs to be retrieved as parameters and returns row data as an array of values
T[] retrieveRow(String table_name, int row_index);
//This function takes table name and index at which data needs to be retrieved as parameters and returns column data as an array of values
T[] retrieveColumn(String table_name, int col_index);
//This function takes table name as parameter and retrieves total data as a matrix
T[][] retrieveData(String table_name);
//This function takes table name, row position and column position as inputs and modifies the values at that position
//Returns true upon successful modification of value and false if there any error.
boolean alterValue(String table_name, int row_pos, int col_pos);
}