Please enable JavaScript.
Coggle requires JavaScript to display documents.
MORE SOPHISTICATED BEHAVIOUR (HASHMAP (HASHSET (AN ARRAY LIST BUT WITH NO…
MORE SOPHISTICATED BEHAVIOUR
OUTLINE
USING LBIRARY CLASSES
READING CLASS DOCUMENTATION
USING LIBRARY CLASSES
THE EXIT CONDITION
MAIN LOOP: STRUCTURE
boolean finished = false;
while (!finished) {
do something;
if (exit condition) {
finished = true;
}
else { do something more;
}
}
COMPARING OBJECTS:
IDENTITY VS EQUALITY
IDENTITY TEST
If (input == "bye" {
}
THIS IS TESTING FOR EXACT MATCH
If(input.equals("bye"))
THIS IS TESTING IT IN MORE GENERAL SENSE - EQUALITY
TEST EQUALITY
GENERALLY USE THE EQUALITY METHOD (input.equals)
== best used for NUMBERS
RANDOM NUMBERS
LIBRARY CLASS Random
import java.util.Random;
Random randomGenerator = new Random();
int rand1 = randomGenerator.nextInt();
int rand2 = randomGenerator.nextInt(100);
GENERATING RANDOM RESPONSES
randomGenerator = new Random();
randomGenerator = new Random();
responses = new ArrayList<String>();
fillResponses();
}
public String generateResponse()
{ int index = randomGenerator.nextInt(responses.size());
return responses.get(index); }
public void fillResponses()
HASHMAP
COLLECTIONS THAT CONTAIN PAIRS OF VALUES
PAIRS CONSIST OF A KEY AND A VALUE
IS BASICALLY AN ASSOCIATIVE ARRAY IN PHP
HASHSET
AN ARRAY LIST BUT WITH NO ORDER
BREAKING UP STRINGS
String[] wordArray = inputLine.split(“ “); // split input