Created
December 17, 2016 17:13
-
-
Save jtcressy/7d3c3497e66e6e4af10042d1b1bd7dca to your computer and use it in GitHub Desktop.
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
import java.util.*; | |
public class Santa { | |
private static int childCount = 100; | |
public static void main(String[] args) { | |
Child[] children = new Child[childCount]; | |
for (int i = 0; i < childCount;i++){ | |
children[i] = new Child(); | |
} | |
makeList(children); | |
checkList(children); | |
checkList(children); | |
verifyNaughtyNice(children); | |
comeToTown(); | |
} | |
public static void makeList(Child[] children){ | |
String[] nameList = {"Danille","Nigel","Felicia","Li","Lajuana","Hershel","Minerva","Susana","Lorelei","Shirely","Davina","Kathe","Penny","Lovie","Emmett","Thresa","Zachariah","Krysten","Deeann","Humberto","Shawnee","Jae","Luba","Francis","Rolando","Markus","Ashlie","Cherrie","Denna","Hayley","Lannie","Kesha","Christinia","Sonny","Kristofer","Frederic","Marielle","Nolan","Dorene","Shenika","Earl","Vincenzo","Crista","Lizzette","Raylene","Stevie","Leandro","Tennie","Sona","Williemae"}; | |
Random rnjesus = new Random(); | |
for (int i = 0; i < childCount; i++){ | |
children[i].name = nameList[rnjesus.nextInt(nameList.length)]; | |
children[i].isSleeping = rnjesus.nextBoolean(); | |
children[i].isNice = rnjesus.nextBoolean(); | |
} | |
} | |
public static void checkList(Child[] children){ | |
int numNaughty = 0, numNice = 0, numSleeping = 0; | |
for (int i = 0; i < childCount; i++){ | |
if (children[i].isNice) | |
numNice++; | |
else | |
numNaughty++; | |
if (children[i].isSleeping) | |
numSleeping++; | |
} | |
System.out.println("Santa knows that there are " + numNice + " nice children and " + numNaughty + " naughty children.\n"); | |
System.out.println("Santa also knows that " + numSleeping + " are asleep.\n\n"); | |
} | |
public static void verifyNaughtyNice(Child[] children){ | |
System.out.println("These children Santa has verified to be naughty: "); | |
for (int i = 0; i < childCount; i++){ | |
if (!children[i].isNice) | |
System.out.print(children[i].name + ", "); | |
} | |
System.out.println("\nThese children Santa has verified to be nice: "); | |
for (int i = 0; i < childCount; i++){ | |
if (children[i].isNice) | |
System.out.print(children[i].name + ", "); | |
} | |
System.out.println("\n"); | |
} | |
public static void comeToTown(){ | |
System.out.println("Santa Claus is Coming To Town!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment