mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-05 01:27:42 -08:00
Convert 20_Buzzword to Java
The original version was a straight forward monolithic BASIC-to-Java conversion. Updated to use common Java coding conventions. - Split the single static main method into classes. The static part only contains the bootstrap code for the game. - Split the word list into three arrays so that there is no need to use error-prone calculations when choosing the random words. - Placed the Scanner in a try-with-resources block to ensure that the scanner gets closed when it is no longer needed.
This commit is contained in:
39
20_Buzzword/java/src/BuzzwordSupplier.java
Normal file
39
20_Buzzword/java/src/BuzzwordSupplier.java
Normal file
@@ -0,0 +1,39 @@
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A string supplier that provides an endless stream of random buzzwords.
|
||||
*/
|
||||
public class BuzzwordSupplier implements Supplier<String> {
|
||||
|
||||
private static final String[] SET_1 = {
|
||||
"ABILITY","BASAL","BEHAVIORAL","CHILD-CENTERED",
|
||||
"DIFFERENTIATED","DISCOVERY","FLEXIBLE","HETEROGENEOUS",
|
||||
"HOMOGENEOUS","MANIPULATIVE","MODULAR","TAVISTOCK",
|
||||
"INDIVIDUALIZED" };
|
||||
|
||||
private static final String[] SET_2 = {
|
||||
"LEARNING","EVALUATIVE","OBJECTIVE",
|
||||
"COGNITIVE","ENRICHMENT","SCHEDULING","HUMANISTIC",
|
||||
"INTEGRATED","NON-GRADED","TRAINING","VERTICAL AGE",
|
||||
"MOTIVATIONAL","CREATIVE" };
|
||||
|
||||
private static final String[] SET_3 = {
|
||||
"GROUPING","MODIFICATION", "ACCOUNTABILITY","PROCESS",
|
||||
"CORE CURRICULUM","ALGORITHM", "PERFORMANCE",
|
||||
"REINFORCEMENT","OPEN CLASSROOM","RESOURCE", "STRUCTURE",
|
||||
"FACILITY","ENVIRONMENT" };
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
/**
|
||||
* Create a buzzword by concatenating a random word from each of the
|
||||
* three word sets.
|
||||
*/
|
||||
@Override
|
||||
public String get() {
|
||||
return SET_1[random.nextInt(SET_1.length)] + ' ' +
|
||||
SET_2[random.nextInt(SET_2.length)] + ' ' +
|
||||
SET_3[random.nextInt(SET_3.length)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user