Advertisement
akosiraff

CharMatrix JAVA

Dec 8th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/charmatrix-java/
  3. Write your instructor a program that gives him the three characters asked for. The matrix to use is:
  4. A B C D E F G H I J
  5. 1 3 N 1 M 4 R X 5 F N
  6. 2 N V T 5 K Q F M 3 P
  7. 3 9 K 1 Y R 4 V T F 3
  8. 4 3 3 9 V 4 Y R T N N
  9. 5 3 1 1 3 2 9 X P N P
  10. A challenge of A1:B2:C3 would yield 3 V 1.
  11. A challenge of G4:D2:J3 would yield R 5 3.
  12. Algorithm
  13. Data: Use a 5×10 matrix to load each the matrix above. See code below.
  14. 1. Create a means to accept data (in Java, instantiate a Scanner object).
  15. 2. Ask for input of the nth challenge.
  16. 3. Separate 1st position and 2nd position of the string (use the substring function)
  17. a. Use an if-else for each A-J possibility, returning the appropriate number. (example A = 0)
  18. b. Change 2nd position to an integer and subtract 1 (use parseInt)
  19. 4. Get the character at the two indices found in 3(a) and 3(b) and display the answer
  20. 5. If this is the last challenge, go to step 6, else go to step 2.
  21. 6. End program
  22. Suggestions:
  23. • Use a method for step 3(a).
  24. • Use a method for step 3(b), but you can do it all in one statement.
  25. • Use multiples classes, if you would like. A driver class and static classes in a class that hold your Array and objects.
  26. • Use a do-while statement to loop through asking the challenges. You know you always will ask at least once, so do-while is appropriate for repetition structures that you know will iterate at least one time.
  27. You can copy and paste the array into your program:
  28. private static String[][] array =
  29. {
  30. { “3″, “N”, “1″, “M”, “4″, “R”, “X”, “5″, “F”, “N” },
  31. { “N”, “V”, “T”, “5″, “K”, “Q”, “F”, “M”, “3″, “P” },
  32. { “9″, “K”, “1″, “Y”, “R”, “4″, “V”, “T”, “F”, “3″ },
  33. { “3″, “3″, “9″, “V”, “4″, “Y”, “R”, “T”, “N”, “N” },
  34. { “3″, “1″, “1″, “3″, “2″, “9″, “X”, “P”, “N”, “P” }
  35. };
  36.  
  37. Download: http://solutionzip.com/downloads/charmatrix-java/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement