Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HI can someone help with 1c I aleady have a and b done Part 2 The questions in this part of the aasignment will be
HI can someone help with 1c I aleady have a and b done
Part 2 The questions in this part of the aasignment will be graded. Question 1: Sort and Find (40 points) For this question, you need to create a class called SortAndFind. Inside such class, you will write several methods to help you sort a 2-dimensional array of integers both row-wise and column-wise. You will also write a method that implements an algorithm to find an element inside the array. Throughout this question, we call a array a matrix, if all its sub-arrays have the same length. To get full marks, you must write the following methods. Note that you are free to write any additional method if they help in the desig or readability of your code. (a) (5 points) la. A method to generate an array of random integers Write a method called generateRandomMatrix that takes as input two integers m and n indicating the dimensions of a two-dimensional array. The method must create an m by n array of integers. It must then populate all its elements with random integers between 0 (included) and 50 (excluded) To do so, create an object of type Random (remember that to use Random you should add the appropriate import statement at the beginning of your file). To make your program easier to debug (and grade), you must provide a seed equal to 123 for the Random object. For example, with the seed of 123, generateRandomMatrix(3,4) returns the following array: [[32, 0, 26, 39], [45, 7, 34, 37], [35, 3, 39, 26]] The order in which you see the numbers might vary depending on how you initialized the elements of the array (b) (2 points) A method to display all the element of a matrix Write a method called displayMatrix that takes as input a two-dimensional array of integers. Thie method should display all the elements of the array, one subarray per line. Separate each element Example, if you call displayMatrix with the array [[32, 0, 26]. [39, 45. 7]. [34, 37, 35]] 32 26 4 3735 If you call displayMatrix(generateRando Matrix(6,8)), then the following must be displayed: 32 026 39 45 7 34 3 using the tab character ("\t'). as input, the following must be displayed: 39 45 35 3 39 26 22 15 3749 0 35 4 16 22 37 36 28 38 42 21 44 1122 30 33 2 25 3 34 35 36 48 42 43 0 14 36 43 (c) (9 points) A method to sort a 1-dimensional array Write a method called sortOneRo that takes as input a one dimensional array of integers. The method should not return any value. The method should sort the array in an increasing order. To do so, you must implement the following algorithm (called selection sort) Idea: consider the array as if it was divided into two parts, one sorted (on the left) and the other unsorted (on the right). Note that at the beginning the sorted part is empty. To implement ageStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started