Get Full Solution Manual Here

Read MoreSave

Read MoreGeneral Information Your analytical work in solving problems is of no value if you cannot communicate it to others. A written report is just one method of doing this. The ability to write clear, concise, accurate, and professional looking reports is as important as the analysis that goes into problem solving. It is…

Read MoreIn a case study you examine a real-life situation with all its complexities to discover what factors might contribute to outcomes. A case study is used to study a particular situation in depth. It is not possible to generalise from the findings of a case study, but it can be used to test whether,…

Read More*8.7 (Points nearest to each other) Listing 8.3 gives a program that finds two points in a two-dimensional space nearest to each other. Revise the program so that it finds two points in a three-dimensional space nearest to each other. Use a two-dimensional array to represent the points. Test the program using the following points:…

Read More**8.6 (Algebra: multiply two matrices) Write a method to multiply two matrices. The header of the method is: public static double[][] multiplyMatrix(double[][] a, double[][] b) To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have…

Read More8.5 (Algebra: add two matrices) Write a method to add two matrices. The header of the method is as follows: public static double[][] addMatrix(double[][] a, double[][] b) In order to be added, the two matrices must have the same dimensions and the same or compatible types of elements. Let c be the resulting matrix. Each…

Read More**8.4 (Compute the weekly hours for each employee) Suppose the weekly hours for all employees are stored in a two-dimensional array. Each row records an employee’s seven-day work hours with seven columns. For example, the following array stores the work hours for eight employees. Write a program that displays employees and their total hours in…

Read More*8.3 (Sort students on grades) Rewrite Listing 8.2, GradeExam.java, to display the students in increasing order of the number of correct answers.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
public class ProgramingEx8_3 { /** Main method */ public static void main(String args[]) { // Students' answers to the questions char[][] answers = { {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}, {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'}, {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'}, {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'}, {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}, {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}, {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}, {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}}; // Key to the questions char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'}; //Array to keep result int[][] result = new int[answers.length][2]; // Grade all answers for (int i = 0; i // Grade one student int correctCount = 0; for (int j = 0; j if (answers[i][j] == keys[j]) correctCount++; } result[i][0] = i; result[i][1] = correctCount; } selectionSort(result); //printing out result for (int j = 0; j System.out.println("Student " + result[j][0] + "'s correct count is " + result[j][1]); } } public static void selectionSort(int[][] list) { for (int i = 0; i // Find the minimum in the list[i..list.length-1] int currentMin = list[i][1]; int currentMinIndex = i; for (int j = i + 1; j if (currentMin > list[j][1]) { currentMin = list[j][1]; currentMinIndex = j; } } // Swap list[i] with list[currentMinIndex] if necessary if (currentMinIndex != i) { list[currentMinIndex][1] = list[i][1]; list[i][1] = currentMin; list[currentMinIndex][0] = list[i][0]; list[i][0] = currentMinIndex; } } } } |

*8.2 (Sum the major diagonal in a matrix) Write a method that sums all the numbers in the major diagonal in an n * n matrix of double values using the following header: public static double sumMajorDiagonal(double[][] m) Write a test program that reads a 4-by-4 matrix and displays the sum of all its elements…

Read More*8.1 (Sum elements column by column) Write a method that returns the sum of all the elements in a specified column in a matrix using the following header: public static double sumColumn(double[][] m, int columnIndex) Write a test program that reads a 3-by-4 matrix and displays the sum of each column. Here is a sample…

Read More***7.35 (Game: hangman) Write a hangman game that randomly generates a word and prompts the user to guess one letter at a time, as shown in the sample run. Each letter in the word is displayed as an asterisk. When the user makes a correct guess, the actual letter is then displayed. When the user…

Read More