Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download: http://solutionzip.com/downloads/charmatrix-java/
- Write your instructor a program that gives him the three characters asked for. The matrix to use is:
- A B C D E F G H I J
- 1 3 N 1 M 4 R X 5 F N
- 2 N V T 5 K Q F M 3 P
- 3 9 K 1 Y R 4 V T F 3
- 4 3 3 9 V 4 Y R T N N
- 5 3 1 1 3 2 9 X P N P
- A challenge of A1:B2:C3 would yield 3 V 1.
- A challenge of G4:D2:J3 would yield R 5 3.
- Algorithm
- Data: Use a 5×10 matrix to load each the matrix above. See code below.
- 1. Create a means to accept data (in Java, instantiate a Scanner object).
- 2. Ask for input of the nth challenge.
- 3. Separate 1st position and 2nd position of the string (use the substring function)
- a. Use an if-else for each A-J possibility, returning the appropriate number. (example A = 0)
- b. Change 2nd position to an integer and subtract 1 (use parseInt)
- 4. Get the character at the two indices found in 3(a) and 3(b) and display the answer
- 5. If this is the last challenge, go to step 6, else go to step 2.
- 6. End program
- Suggestions:
- • Use a method for step 3(a).
- • Use a method for step 3(b), but you can do it all in one statement.
- • Use multiples classes, if you would like. A driver class and static classes in a class that hold your Array and objects.
- • 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.
- You can copy and paste the array into your program:
- private static String[][] array =
- {
- { “3″, “N”, “1″, “M”, “4″, “R”, “X”, “5″, “F”, “N” },
- { “N”, “V”, “T”, “5″, “K”, “Q”, “F”, “M”, “3″, “P” },
- { “9″, “K”, “1″, “Y”, “R”, “4″, “V”, “T”, “F”, “3″ },
- { “3″, “3″, “9″, “V”, “4″, “Y”, “R”, “T”, “N”, “N” },
- { “3″, “1″, “1″, “3″, “2″, “9″, “X”, “P”, “N”, “P” }
- };
- Download: http://solutionzip.com/downloads/charmatrix-java/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement