Title: The Programming Discipline
1The Programming Discipline
Revisited with Java examples
- Professor Stephen K. Kwan
2- The Programming Project
-
- Problem statement create an online Mortgage
Calculator
- Purpose provide a user-friendly service to
potential users for accurately planning mortgage
and other types of loans
- Scope Web-based, platform-independent, single
user client-side application with validation and
meaningful input/output.
3- The Problem Solution Approach
- Algorithm standard loan calculation with fixed
number of payments
- Payment Principal (InterestRate / (1
(InterestRate 1) 12 Periods)
- Inputs Principal, InterestRate, Periods
- Output Payment
- Where InterestRate is the rate for each payment
period in decimals
- for example if the annual mortgage interest
rate is 5.0, then
- the InterestRate used here is 5.0 / 100 / 12
0.00416666
- assuming the payment period is in months.
- GUI with Event-Based Programming - Interactive
4- Diagrammatic Aids layout of screen
Inputs
Outputs
5- Diagrammatic Aids Class Diagram
6- The Operating Environment
- Web HTTP use a HTML file to transport the
application to client
- Use a browser as the client-side application
launcher assume support of JRE?
- Cross-Platform functionality
- Choosing the Programming Language Text/GUI,
purpose
- Java general purpose, Text or GUI,
cross-platform functionality with Java Runtime
Environment within a browser assume knowledge
and availability of JDK
7- The Primitives of the Language objects,
variables, data types, declarations, numbers,
strings, etc.
inherits
public class mortgage extends Applet
implements ActionListener int intMon, intYea
r double dblInterestPayment Font fntRegular
new Font (Serif,Font.Bold, 18)
Label lblYears new Label(Years)
TextField txtReturnRate new TextField(,5)
Button resetButton new Button(Reset)
String public void init ( )
Object
Interface
Declarations
Method
Component
8- The Input/Output (I/O) System
- Arithmetic Expressions and Assignment Statements
- dblMonthly dblPrincipal (dblInterest /
- (1-Math.pow(dblInterest1,-12.0intYear)
- Decision Making and Logical Expressions
- if ( strValue.length( ) 0 )
-
- else
-
GUI TxtFields and Labels, layout managers
Screen rendering by Browser
or Applet Viewer
9- Support of Structured Programming Techniques -
Yes
Repetition while ( condition)
do
while ( condition )
Sequence Yes Selection if (condition) e
lse if (condition) switch ( choice
) case 1 . Break case 2
. Break default
10- Functions and Subroutines modules - methods
- public boolean Validate (TextField strParam, int
intReturn)
-
- return true
-
- Event-based Programming for GUIs, Interface
Design - components
public class mortgage extends Applet
implements ActionListener txtPrincipal.add
ActionListener(this) public void actionPerfor
med(ActionEvent evt)
11- Internal Storage - Arrays and Data Structures -
NA
- External Storage - Files and Databases- NA
- Error Detection and Handling
- try
- code segment which might generate error
-
- catch (NumberFormatException err)
-
- code to handle the error condition
-
-
Example of error condition to be detected
Actual error
1217. Input Validation (general)
Existence Check
Domain Check
Field Value Exists ?
Start
T
Value is Valid Type ?
F
T
No Input Entered
Size of Value Is Valid ?
T
F
Invalid Input Type
Value within Valid Range ?
Process The Input Data
F
Invalid Input Size
F
Invalid Input Value
13- Output Formatting
- text package, format classes
- Projects and Programming Tasks
- Files, Packages, IDE
- Operational issues compile/link/execute
- JavaC, JavaR, importing classes
- Deployment, Version Control, etc.
End