:::::::::::::: Question01.java :::::::::::::: /** * LABTEST 2 (PRACTICE) - EECS1710, F2018 * * * FIRST NAME: XXXXXXXXXXXXXXXXXXXXX * LAST NAME: YYYYYYYYYYYYYYYYYYYYY * LOGIN: ZZZZZZZZZ * * SID: SSSSSSSSS * * * */ // QUESTIONS TO ANSWER + INSTRUCTIONS ARE IN MAIN METHOD BELOW public class Question01 { // This method will print out a 2D array (DO NOT MODIFY) public static void printGrid(int[][] grid, int m, int n) { // This method will print out the m x n array // DO NOT CHANGE THIS METHOD for (int i=0; i < m; i++) { // iterates over rows for (int j=0; j < n; j++) { // iterates over columns System.out.printf("%5d",grid[i][j]); // there was a typo here (missing grid[i][j]) } System.out.println(); } } // This method is for part 1b - you need to modify and complete it public static int sumColumn(int[][] grid, int col) { int sum = 0; // COMPLETE THIS METHOD (for Part 1b) int M = grid.length; // extracts first dimension int N = grid[0].length; // extracts second dimension for (int i=0; i words1 = // =========================================================================== // SINCE THIS QUESTION ASKS YOU TO USE ARRAYLIST (WHICH WE HAVENT LEARNED YET) // I WILL PROVIDE A SOLUTIONS ARE GIVEN IN TERMS OF ARRAYS ONLY! // =========================================================================== String [] wordsScanned = new String[100]; // dont know how many words, so lets allow for 100 // can trim after int i=0; // index of next word Scanner inSentence1 = new Scanner(sentence1); // scanner to read individual words while (inSentence1.hasNext()) { wordsScanned[i] = inSentence1.next(); // get next word from scanner i++; // increment index (very important!!) } // no hasNext(), so must be done, current value of i lets us know how many words read // copy only words scanned to create words1 String [] words1 = new String[i]; // there are i words! for (int j=0; j Keyboard input - i.e. System.in // ==> File input - i.e. a File that has been opened // ==> String input - i.e. a String that has been created or read from keyboard // once Scanner is connected to one of these, it can be used in a // standard way i.e. using hasNext(), hasNextInt(), next(), nextInt() // or nextDouble() methods etc. Scanner inSentence2 = new Scanner(sentence2); // Using the above Scanner object, write a while loop to automatically (not // manually) scan and add each word from sentence2 into a new ArrayList object // called "words2". Words should only be added if they do not exist in // the "words1" ArrayList. // // Output the ArrayList "words2" to the screen (use similar format as used in // part 2(b)) // // [Hint: While not needed to do this task, the contains() method defined // in the ArrayList API will make it much easier] // // YOUR CODE FOR PART 2(c) GOES BELOW boolean done = false; String [] words2 = new String[words1.length]; // words2 is at least the length of words1 int numWords2 = 0; String nextWord; while (!done) { // the solution for this is much simpler with Arraylist, however a solution // using Arrays is shown below if (!inSentence2.hasNext()) { done = true; } else { nextWord = inSentence2.next(); // for each word extracted , check if it exists in words1 boolean wordExistsInWords1 = false; for (int currWord=0; currWord