Java Reference
In-Depth Information
Pseudocode
Pseudocode is a program design technique that uses natural English and resembles Java code. It is an
intermediate notation that allows the logic of a program to be formulated without diagrams or charts.
Pseudocode resembles Java code in that specific operations can be expressed as commands that the
program will execute. The following three examples illustrate pseudocode:
Accept Employee Record
MaleCounter = MaleCounter +1
Display Employee Record
What makes pseudocode appealing to many programmers is that it has no formal syntax, which
allows programmers to concentrate on the design of the program rather than on the peculiarities of
the programming language's syntax.
Although pseudocode has no formal rules, the following guidelines are commonly accepted by
most programmers:
1. Begin the pseudocode with a program, procedure, or method title statement.
Monthly Sales Analysis Report Procedure
2. End the pseudocode with a terminal program statement.
End
3. Begin each statement on a new line. Use simple and short imperative sentences that contain a
single transitive verb and a single object.
Accept EmployeeNumber
Subtract 10 From Quantity
4. Express assignments as a formula or as an English-like statement.
WithholdingTax = 0. 20 3 (GrossPay - 38.46 3 Dependents)
or
Compute WithholdingTax
5. To avoid errors in the design, avoid using logic structures not available in the programming
language being used.
6. For the If…Then…Else structure, use the following conventions:
a. Indent the true and false tasks.
b. Use End If as the structure terminator.
c. Vertically align the If, Else, and End If statements.
The conventions for the If…Then…Else structure are illustrated in Figures A-12 and A-13. (Java
implements the structure in code with the keywords, if and else.)
Search WWH ::




Custom Search