-
Text Processing
-
The char Type
- 'c'
- 2byte, Unicode
- really integers
- ==,<,>
-
Cumulative Text Algorithms
-
static methods
- Charactor
-
System.out.printf
-
'f' formatted
- %
-
Methods with Conditional Execution
- Precondition
- Postconditions
-
Throwing Exceptions
- exceptions are objects
- create new exception object and then throw it
- if(n<0) {throw new IllegalArgumentException();}
- when thrown, it halts the execution of the method
- Reasoning about path
-
case study
- main method: short; structure
-
Good structure
-
Each method should have coherent set of responsibilities
- method can be described in one sentence
- No one method should do too large a share of the overall task
- coupling and dependencies between methods should be minimized
-
The main method should be a concise summary of overall prog
- less chaining
-
Data should be "owned" at the lowest level possible
- main should not have too much println
- if data need to pass down to some level, it should be defined in a lower level
-
Cumulative Algorithms
-
Cumulative Sum
- sum=sum+next;
-
Min/Max Loops
- initialize;
- for(){if(min>next) or if(max<next)}
-
Cumulative Sum with if
- Consider special cases
-
Roundoff Errors
- Compare doubles:Math.abs(a-b)<0.001
-
if/else Statement
- Relational Operators
-
if/else options
- sequential ifs
- nested ifs ending in test
- nested ifs ending in else
-
Equality
- Primitive data: ==/!=
- Objects: .equals(); equalsIgnoreCase()
-
Multiple Conditions
- logical AND &&
- logical OR ||