Java: CMIS 102A - Program Prototypes
These typical programs should be mastered by introductory Java students. They use both console and dialog I/O.
Sequential control flow
Topics
- Style: Comments, class name, good variable names, indentation, named constants.
- Structure: import, class definition, main, semicolons, braces.
- Types: int, double, String.
- Actions: Assignment, arithmetic operators (+ - * / %).
String concatenation (+) and methods (substring, length, indexOf, lastIndexOf).
Program | IO | Data | Flow | Java constructions and programming concepts |
---|---|---|---|---|
DoNothing.java | None | - | - | Class definition, main definition. |
HelloEarthlingC.java | Console | String | Seq. | System.out.println(...) |
HelloEarthlingD.java | Dialog | String | Seq. | String literal.JOptionPane.showMessageDialog(null, ...) |
ToYourLeader.java | Console | String | Seq. | Concepts: Variable, assignment, input, declaration.
import java.util.*;
Scanner in = new Scanner(System.in);
in.next()
JOptionPane.showMessageDialog(null, ...) |
- Initials.java - Read text, perform calculation/transformation, display result.
- KmToMiles.java - Read a number, perform calculation, display result.
Conditional control flow using if statements
Topics
- Style: Indentation. "Paragraphs" for initialization, input, processing, output.
- Structure: if clauses, nested if statements.
- Types: boolean, primitive vs. object reference.
- Actions: Numeric comparison ops (< <= == != >= >),
String comparisons (equals, equalsIgnoreCase, compareTo, compareToIgnoreCase),
Logical ops (&& || !).
Programs
Loops
Topics
- Style: Indentation.
- Structure: while, for, do-while statements, break.
- Variants: Loop backwards (for), loop over all chars in a string (f0r), loop while input (while).
Programs
- xx - Displaying message in a while loop.
- xx - Counting in for loop.
- MaxMin.java - Maximum and minimum of a series of numbers.
- Average.java - Average of a series of numbers.
- CountBlanks.java - Count blanks in a string.
- - Ulam sequence.
Copyleft 2006 Fred Swartz