-
-
Save benjholla/dc45ca6926ec162aa59394c646754166 to your computer and use it in GitHub Desktop.
Group assignment algorithm for classroom assignment activity 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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