Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Try solving this using only the methods from the first Java course (css142) (e.g like for loops, arrays, if statements and the likes). Please try

image text in transcribed

Try solving this using only the methods from the first Java course (css142) (e.g like for loops, arrays, if statements and the likes). Please try to keep it simple and not using advance methods. I'm still trying to learn the basics and won't understand very complicated methods.

Thank you!

Homework 8 double getValAt(int i, int j): returns the double value stored in row i column j. If either i or j is out-of-bounds, you should return NaN and print a message to the indicating this problem: void sort boolean byColumn): sorts the invoking two-dimensional array using the selection sort algorithm. You may use an auxiliary array here, however note that this method is void and thus you must modify the invoking CSS 142 Instructions: Please submit your files to the Canvas submission page for this assignment by the due date. Late homework will not be graded. Grading Rubric: 70% for correctness . includes: following the requirements of each problem as stated (it is your responsibility to ask for clarifications): using the concepts learned from class: testing your code for correctness; having code that works. 30%for style-includes: commenting (block and in-line): spacing between operator and operands: obeys style guidelines indicated during lectures. array. Also notice that it should take as a parameter a boolean byColumn this parameter will determine whether or not the array should be sorted by column (that is, if byColumn is true, then sot by column). For example, given a 2-D array below (left), we can sort it in two ways-by row (middle) or by column (right) 123 456 789 1 47 2 58 3 69 486 Purpose: In this homework you will gain more practice writing classes and instantiating objects. You will also practice programming using 2-D arrays 9 27 135 MDArray Part a: Write a class called MDArray containing the following variables and methods: Note: Sorting by row should work on any 2-D array (ragged or not). However, sorting by column should only work for non-ragged arrays and should print a cannot sort ragged arrays by column" message to the screen if the method is invoked by a ragged array. If this happens, you should simply print the message and not modify the array -there is no need to exit the program: 1. Private data field: mdarray of type double[Dl 2. Public constructors: your class should have two constructors-one that takes a 2-D int hamming/boolean byColumn): returns the hamming distance of the invoking array of doubles and another one that takes a text file name as a String. For the latter one, the text file will contain a 2-D array where the first line is an int representing the number of rows in the array, and each line below that has an int representing the length of the row followed by the values that represent that row in the 2-D array. For example, if the contents of the text file is as follows: array from its sorted state (by row or by column. depending on the passed in argument). The hamming distance of a 2-D array can be defined as follows: each number that is not where it should be (as in the sorted state) is worth one penalty point. For example, if the invoking matrix is: 486 297 135 24.1 8.9 9.5 2.0 7.32.18.931.35.2 3.4 then its hamming distance is 9 from its by-row sorted state and 8 from its by column sorted state. Note: If the invoking array is ragged and the boolean byColumn is true. you should return the code-1 to indicate that there is no by-column hamming distance for ragged arrays: doublell max): returns the row in a 2-D array that contains the maximum value in the entire 2-D array: String toString) : returns the string representation of the invoking array. Each value should be comma separated and each row should be in a new line when printed to the screen. You may have autonomy on however prettier you wish the print out to be: then it represents a ragged 2-D array with 3 rows, where the first row has length 2, the second one 5 and the third one 3. 3. Public methods: boolean isRagged): returns true if the invoking 2-D array is a ragged array: int getNumberOfRows): returns the number of rows in the array: int getNumberOfCols(): returns the number of columns in the array. If the array is ragged, it should return the maximum length row in the array: MDArrayDemo Part b: In a class called MDArrayDemo, write a main method to test each of your constructors and methods from the MDArray class. Make at least five distinct MDArray objects (3 non-ragged and 2 ragged-use may use Math.random). but at least one of them must be constructed using a file input). Important: Please follow the API provided above. That is, use the method names and signatures as provided for the public methods. You may have other helper methods, but they must be private! I will be testing your code automatically with my own test files and classes

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

Would you rather have higher pay or better benefits? Why?

Answered: 1 week ago

Question

Does it avoid use of underlining?

Answered: 1 week ago