Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Conditionals and Boolean Logic9/16/2009Opening Discussion●Do you have any questions about the quiz?●How is the reading going? Please suggest changes or let me know when you find errors/typos.●Minute Essays–Loops are next week–Basic Java environments: BlueJ.–Doing unrelated things is distracting to others.–Answers of ICPs.Our Problem●The walkToward method has a problem if dx or dy are zero. Specifically, we get a division by zero exception.●We only want to do the division if the value is greater than zero.●We might also want the person to do something when it gets where it is going.Conditional Execution●Methods execute by having the statements happen in order.●Right now, all the statements in a method will happen any time that method is invoked.●We need the ability to make it so that some things only happen some of the time. This is called conditional execution.●The simplest conditional is the if statement.Syntax of if●We will normally write an if statement with the following syntax.–if(condition) {●statements–} [ else {●statements–} ]●The statements only execute if the condition is true.●Else is optional executes if condition is false.Comparison Operators●If you want to compare two numbers use the following.–== for equality. Note there are two of them.–!= for inequality.–>, <, >=, <= for what they look like.●With objects you generally want to call the equals method.–if(v1.equals(v2)) ...Boolean Logic●We only want the person to enter the house if both dx and dy are zero. To do this we use Boolean logic.●Logic operators–|| is inclusive or.–&& is and.–! is not.●Let's look at truth tables for these.●Use parentheses to group things.Minute Essay●Do you have any questions about conditionals or Boolean logic?●The next round of interclass problems will be this coming
View Full Document