Conditionals and Introduction to Methods
New Terminology
- logical expression
- An expression which uses a logical operator. Will evaluate to true or
false.
- logical operators
- && = AND
|| = OR
! = NOT
- constructor
- The method which initializes an object as it is created
(instantiated) from the class
- method
- A block of code which can be executed by calling or invoking the code
header. May accept parameters and may return a value.
- parameters
- Values that are passed into a method or function or variables which
accept those values.
- arguments
- Values that are passed into a method
- formal parameters
- Variables that accept arguments in a method or function
- return value
- The value that a method returns.
Programming specific structures and terms
- nested if
- An if/else statement that is inside another if/else structure.
- method header
- The line that introduces the method. Includes visibility, method name, return type and formal parameter list.
- method declaration
- The code that begins with the method header and ends with the final curly brace.
- void
- A java keyword that signifies that a method returns nothing.
- constructor
- The method which initializes an object as it is created
(instantiated) from the class
Class notes
- Lab Review - DivideBy0.java & BadInput.java
- Intro to Logical Operators and Nested ifs - NestedIfLogical.ppt
- nested if (cascade) - TestResults.java
- nested if (one branch) - LoanQualifier.java
- logical AND - LogicalAnd.java
- logical OR - LogicalOr.java
- comparing characters and Strings - StringCompare.java
- Intro to methods
- Methods let us divide and conquer the program
- Use methods where
- You want to reuse the code - see Math class methods
- You want to simplify the program - remember we can remember 5-7 things
- There are natural divisions of labor in the program
- input
- output
- calculation
- Example in BadInputV2. & InputHelper.java