Question: CODE: public class TestGenericSorting { public static void main(String[] args) { Integer[][] grid = {{32, 19, 27, 90}, {100, 22, 29, 23}, {34, 1, 45,

 CODE: public class TestGenericSorting { public static void main(String[] args) {
Integer[][] grid = {{32, 19, 27, 90}, {100, 22, 29, 23}, {34,
1, 45, 37}, {397, 49, 76, 63}, {204, 95, 77, 49}, {47,
CODE:
public class TestGenericSorting
{
public static void main(String[] args)
{
Integer[][] grid = {{32, 19, 27, 90},
{100, 22, 29, 23},
{34, 1, 45, 37},
{397, 49, 76, 63},
{204, 95, 77, 49},
{47, 54, 13, 11}};
Double[][] grid2 = {{1.9, 3.4, 0.45 , 23.9, 34.5},
{1.49, 6.37, 7.54, 5.43, 3.46},
{50.76, 112.24, 19.6, 19.99, 45.3}};
Integer[][] grid3 = {{95, 34, 87, 300, 899, 6},
{99, 32, 777, 900, 87, 4},
{3, 9, 430, 235, 102, 32},
{45, 34, 98, 23, 190, 19},
{93, 54, 86, 84 ,27, 19},
{234, 54, 67, 20, 200, 123},
{30, 7, 19, 22, 34, 31}};
GenericSorting srt = new GenericSorting(grid);
srt.sortAsc();
srt.print2DArray();
System.out.println();
srt.setGrid(grid2);
srt.sortDes();
srt.print2DArray();
System.out.println();
srt.setGrid(grid3);
srt.sortAsc();
srt.print2DArray();
System.out.println();
/*
GenericSorting srtFile = new GenericSorting("src/project1/data.txt");
srtFile.sortAsc();
srtFile.print2DArray();
*/
}
}
DATA.txt
500 3 9 7
11 2 14 10
25 1 19 15
342 21 16 29
204 54 23 43
42 27 15 11

In IntelliJ, create a project name Project1, then create a new package under that project named project 1 Create a new java class named GenericSorting. Declare a Generic 2-diminssional instance array named grid. - Create a constructor that receives a 2-dimissional Generic array as a parameter and sets the instance array grid to the parameter array. Create a getter and setter method for grid. - Create a method named sortAsc, the method doesn't take any parameters and doesn't return any value, the method sorts the instance array grid in an Ascending order. - Create a method named sort Des, the method doesn't take any parameters and doesn't return any value, the method sorts the instance array grid in a Descending order. - The sort method should sort the Generic instance array grid by the numeric values of the array elements. Hint: You may find the compare To method very helpful here. Create a method called print 2DArray which takes no parameters and doesn't return any value, the method prints the instance array grid (Provided in the lecture slides). You may not convert the 2D array to a 1D array and sort it, the sorting should be in- place, which means it sorts the array only by modifying the order of the elements within the same array . You may not use any of the Java API sorting methods to sort the array, in other words, sorting the array is the main task in this project and should be done by you, if you use any of the Java API sorting methods or any external sorting method, you will not receive any credit for the project. You may not add any additional methods. You have been provided with TestGenericSorting java that has the main method, after completing GenericSorting.java, compile both classes and run Test GenericSorting.java, and compare your output to the expected output. Samples: Original Array Sorted Array(Asce ing): 19 27 90 1 11 13 19 8 18 100 22 29 23 22 22 27 29 34 1 45 37 32 34 37 45 397 49 76 63 47 49 49 54 204 95 77 49 63 76 77 90 47 54 13 1 95 100 204 397 Original Array Sorted Array(Descending) 1.9 3.4 0.45 23.9 34.5 112.24 50.76 43.3 34.5 23.9 1.49 6.37 7.54 5.43 3.46 19.99 19.6 7.54 6.37 3.43 50.76 112.24 19.6 19.99 43.3 3.45 3.4 1.9 1.49 0.43 Extra Credit: The arrays in your program are hard coded in the main method, but you can read those arrays from different sources, one option will be a text file. If you can make your program to read an array from a text file then sort it, you will receive 596 as extra credit. Here is what you need to do: Add the text file to the same directory as your java files. Create a new constructor in GenericSorting class, this constructor takes a String as a parameter, this String will contain the name of the text file you want to read. Create a method named readFile() this method takes a String parameter which is the file name, and returns a Generic 2-dimissional array that contains all the values stored in the You can assume that the text file will always have multiple lines, and there are the same number of elements on each line, a sample of this file is provided in the needed files. To make it easier for you. You can assume that this file contains INTEGERS ONLY. You may create new arrays in this method if you need to create a generic array, here is how it's created TO arr = (T00) new Comparable[ 4 ][3]; Java doesn't allow the creation of Generic Arrays directly. You must create an array of Comparable objects, then cast it to a Generic array. To test your work, uncomment the code in the main method and TestGenericSorting.java run

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!