2004 ICS4M FINAL EXAM-JavaWednesday, June 9th. 9:00 a.m.INSTRUCTIONS TO STUDENTS.
|
|||
Question 1. RECURSIVE ALGORITHM. (Degree of Difficulty:1.2) | |||
PermutationsPreamble. The ability to generate the set of all possible permutations of a string of characters is a useful utility to have. A permutation is simply a rearrangement of letters. For example, the string "stop" has 24 permutations. Here's an idea of how to generate the permutations recursively. Consider the string "stop" and let's simplify the problem. First, we'll generate all permutations that start with the letter 's', then those that start with 't', and so on. How do we generate the permutations that start with 's'? We need to know the permutations of the string "top". But that's the same problem - to generate all permutations-with a simpler input, namely the shorter string "top". Thus, we can use recursion. For each permutation of the substring "top", we can prepend the letter 's' to get the permutations of "top" that start with 's', namely, stop Now let's turn our attention to the permutations of "stop" that start with 't'. We need to create the permutations of the remaining letters "sop". That process will yield sop We add the letter 't' to the front of the strings and obtain, tsop We generate all the permutations that start with 'o' and 'p' in the same way. Task. Write the Java application, Permutations.java, that will produce output similar to the screen capture above. You might consider generating all permutations of the original string and storing them in a TreeSet or some such structure for easy lookup of the possible permutation. |
|||
Question 2. DATA STRUCTURE. (Degree of Difficulty:1.0) | |||
CircularListPreamble. In the children's game hot potato, a group of n children sit in a circle passing an object, called the "potato", around the circle. The potato begins with a starting child in the circle, and the children continue passing the potato until a leader rings a bell, at which point the child holding the potato must leave the game after handing the potato to the next child in the circle. After the selected child leaves, the other children close up the circle. This process is then continued until there is only one child remaining, who is declared the winner. Task. Develop the Java application, HotPotato.java, that simulates this game. In support of your application, you will incoporate the class, CircularList.java, that encapsulates a LinkedList object to model the circular list (ring). Your CircularList class should contain overloaded constructors of the form, public class CircularList( Object[] L, int k) so that it could handle arrays of differnt types. To confirm that your code is working, CircularList({1,2,3,4,5},3) is 1, and CircularList({1,2,3},2) is 2. Assume the game begins with the the hot potato being at the first object in L. Submit the two classes, with HotPotato.java including the following tests: L=(Alice,Bob,Charles,Darwin,Ed,Fred,George,Holly,Irene), k=5 Note that the first three of the above are arrays of are Strings, whereas the fourth is an array of integers, and the last one is an array of doubles. |
|||
Questions 3. Java3D. (Degree of Difficulty:1.1) | |||
Java3DDevelop a Java3D scene graph for any one of the following objects. Include Mouse Rotate and Mouse Zoom capabilities into the scene. Click on any thumbnail image for a larger view. |