Instantly share code, notes, and snippets.

@benjholla /ClassActivity1.java Secret
Last active Aug 24, 2018

Embed
What would you like to do?
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