Details of this Paper

Java And Processing Language + Randomness and array manipulations

Description

solution


Question

Submit one sketch per whole number. In other words, the a, b, c, etc., steps are just to help you build your way to a solution. The final letter represents the final deliverable.;Question 1 - Randomness and array manipulations;You are a promising junior programmer in a video game business. You are part of a team working on an online gaming system for a first-person shooter game. In the game, players can register to an arena to play together. Sometimes, they play solo, sometimes, they play in teams.;You have been asked to implement a set of functionalities in Processing (!) to be able to shuffle and make subgroups of players to play in teams.;Each player is identified by its username (a String object).;Start from this code: A1_Q1.zip. The sketch declares empty methods that you need to implement (called "stubs"). It also contains a list of usernames on which it performs a series of tests. You can see the correct expected result of these tests here: undefined Screen Shot 2014-02-02 at 5.07.41 PM.png. If your functions are implemented correctly, you should get similar results. Note that the results of the last test may slightly vary since it involves randomness.;1a - Randomize list;Implement the following method without using ArrayList (ie. using only arrays).;/**;* This method takes a list of usernames and randomizes it.;* @param userNames the list of usernames;* @return a new array containing the randomized list of usernames;*/;String[] createShuffledList(String[] userNames) {};Important;There should be no repetitions in the usernames (unless there was a username twice in the list sent as a parameter).;The returned list should contain all and only the items from the original list. This means that it will have the same length (among other things).;The list of usernames sent as a parameter should not be modified (ie. be aware that you are passing by reference).;1b - Grouping;Implement the following method without using ArrayList (ie. using only arrays).;/**;* This method takes a list of usernames and separates them in different groups.;* @param userNames the list of usernames;* @param nGroups the number of groups;* @return an array of groups of usernames;*/;String[][] createGroups(String[] userNames, int nGroups) {};Example;String[] userNames = loadStrings("usernames.txt"), // you can define your own file with usernames for testing purposes;Stringp[][] groups = createGroups(list, 3);will return an array "groups" where groups[i][j] contains the j-th username of the i-th group. Another way to say it is that groups[i] is an array of String (ie. String[]) containing the usernames of its group.;Important;If nGroups is smaller than 1, it should be considered equal to 1 (ie. one group with everyone in it).;if nGroups is larger than the number of usernames in the list, it should be considered equal to the number of usernames (ie. one person per "group").;If the list has length 0 or is null, the method should return null.;The returned array length is equal to the number of groups ie. groups.length == nGroups.;There should be no repetitions of usernames anywhere in the returned array and all usernames should be there.;When the number of usernames sent as a parameter cannot be perfecly divided by nGroups, you will have to return a mix of groups of different sizes. When that happens;You need to make sure that the difference in size between two groups does not exceed 1. For example, if you call createGroups(list, 3), the result should be an array of groups where each group contains either 2 or 3 usernames.;The bigger groups should be at the beginning of the returned array, the smaller groups at the end.;Groups are formed sequentially, in the order of the elements found in userNames. So for instance, userNames[0] should appear in the first group and userNames[length-1] should always be in the last group.;1c - Randomized groups;Add an optional boolean to the last method: when true, the usernames will be randomized instead of being chosen sequentially.;/**;* This method takes a list of usernames and separates them in different groups.;* @param userNames the list of usernames;* @param nGroups the number of groups;* @param randomize if true, the groups will contain shuffled usernames, if false, the usernames will be added sequentially to the groups;* @return an array of groups of usernames;*/;String[][] createGroups(String[] userNames, int nGroups, boolean randomize) {};Tip: If you have completed 1.1 and 1.2 you should be able to use your createSuffledList() method to shuffle the usernames before adding them to the groups.

 

Paper#70377 | Written in 18-Jul-2015

Price : $37
SiteLock