Guest User

Untitled

a guest
Jan 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class GradeExam {
  3. public static void main(String[] args) {
  4. char[][] answers = {
  5. {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
  6. {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
  7. {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
  8. {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
  9. {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
  10. {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
  11. {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
  12. {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}};
  13.  
  14. char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
  15.  
  16. //Create new array to sort students
  17. int[][] student = new int[8][8];
  18.  
  19. //Echo the answers
  20. String result = "The answer key to the test: \n";
  21. for (int k = 0; k < 10; k++) {
  22. result += keys[k] + " ";
  23.  
  24. }
  25. for (int i = 0; i < answers.length; i++) {
  26. int correctCount = 0;
  27. //Convert grades to a String
  28. String result2 = "Student " + (i + 1) + "'s answers are: \n";
  29. for (int j = 0; j < answers[i].length; j++) {
  30. result2 += answers[i][j] + " ";
  31. if (answers[i][j] == keys[j])
  32. correctCount++;
  33. student[i][0] = correctCount;
  34. student[i][1] = i;
  35.  
  36. }
  37.  
  38. //Display the input
  39. JOptionPane.showMessageDialog(null, result + "\n" + result2 +
  40. "\nStudent " + (i + 1) + "'s correct count is " + correctCount);
  41. }
  42.  
  43. bubbleSortMulti(student);
  44. }
  45.  
  46. public String[][] bubbleSortMulti(String[][] MultiIn, int compIdx) {
  47.  
  48. String[][] temp = new String[MultiIn.length][MultiIn[0].length];
  49.  
  50. boolean finished = false;
  51.  
  52. while (!finished) {
  53. finished = true;
  54.  
  55. for (int i = 0; i < MultiIn.length - 1; i++) {
  56.  
  57. if (MultiIn[i][compIdx].compareToIgnoreCase(MultiIn[i + 1][compIdx]) > 0){
  58.  
  59. for (int j = 0; j < MultiIn[i].length; j++) {
  60. temp[i][j] = MultiIn[i][j];
  61. MultiIn[i][j] = MultiIn[i + 1][j];
  62. MultiIn[i + 1][j] = temp[i][j]; }
  63.  
  64. finished = false;
  65. }
  66. }
  67. }
  68. return MultiIn;
  69. }
  70. }
  71.  
  72. ----jGRASP exec: javac -g GradeExam.java
  73.  
  74. GradeExam.java:43: bubbleSortMulti(java.lang.String[][],int) in GradeExam cannot be applied to (int[][])
  75. bubbleSortMulti(student);
  76. ^
  77. 1 error
  78.  
  79. ----jGRASP wedge2: exit code for process is 1.
  80. ----jGRASP: operation complete.
Add Comment
Please, Sign In to add comment