Skip to content

Instantly share code, notes, and snippets.

@benjholla
Last active August 24, 2018 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjholla/dc45ca6926ec162aa59394c646754166 to your computer and use it in GitHub Desktop.
Save benjholla/dc45ca6926ec162aa59394c646754166 to your computer and use it in GitHub Desktop.
Group assignment algorithm for classroom assignment activity 1
public class ClassActivity1 {
/**
* Prints Student , Group ID
*
* @param args[0] is student first and last name
* Example: java ClassActivity1 "Ben Holland"
*/
public static void main(String[] args) {
String studentName = args[0];
char[] characters = studentName.toUpperCase().replaceAll("\\s+", "").toCharArray();
int groupID = 0;
if (characters.length >= 3) {
int maxGroups = 5;
// Note that 'A' == 65, 'A' = 0x41
int asciiSumFirst3Chars = (int) characters[0] + (int) characters[1] + (int) characters[2];
groupID = asciiSumFirst3Chars % maxGroups;
}
System.out.println("Student: " + studentName + ", Group: " + (groupID + 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment