Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Keyboard Input2/4/2009Opening Discussion●Minute Essay responses–Fuzzy logic–Variable names, different names for the same things?–Order of statements in methods is important. They happen in the order you write them. Order of methods doesn't matter.–We ignored the boolean return on enterHouse.–enterHouse always happens. Doesn't do anything if not on the house.More Responses–Boolean logic can be confusing, requires some thought. Definitely expands our options.–Role of the getWorld() method.–Can you nest if statements?–Can multiple people enter different houses in the world?Goal for the Day●Today I want to make it so that you can control the movement of the person on the screen with the arrow keys.●How should we go about doing this?Keyboard Input●If you look in the API you will find that the Greenfoot class has a method called getKey().●What is the return type of this method? What does the API say the value of this return will be?Strings●A string is a sequence of characters. Words and sentences are strings.●The type of strings in Java is String. Note it starts with a capital letter.●We write string literals in Java by putting whatever we want in quotes.●The web page has a link to the API page for String.Key Methods of String●equals(String s) - This was mentioned last class as the proper way to compare object types.●length() - Returns the number of characters in the string.●indexOf(...) - Many options for arguments. Returns the location in the string where first found.●+ - Not really a method. The plus sign is overloaded in Java to do String concatenation.Printing●Sometimes you need more information than what is being displayed on the world to figure out what a program is doing.●You can print and whatever you print will appear in the console.●To do this use the System.out.println() method. You can pass it one argument of basically any type.Writing the Code●Now we can make it so that the person moves based on keyboard input.●Where should this code go?●What should it look like?Minute Essay●Do you have any questions about what was covered today? Is it clear how to use keyboard input in Greenfoot?●Feel free to do multiple interclass problems. Practice is key to learning
View Full Document