CPS 1 - Spring, 1999 - Ramm 1/27/99 #6
- Announce
- Quiz Today
- Continue to Read Chapter 2
- Lab #2 Starts Tomorrow
Chapt 1. An Introduction to Programming: Coding Decision Trees
- Using Primitive Data Types: Integers
- Does not require a
new statement to create
- Primitive types not classes
- Must declare
- Should initialize (Java sets to 0)
- Other primitive types include: boolean, char, float
- Example Using Integers.
Count.java,
count.html
- Example Doing Multiple Tallies
Tallies.java,
tallies.html
- Used Integers and Plus Operator
- All five integer operators:
-
+, -, *, /, %
- Operator Precedence
Strings and String Manipulation
- The
String Class
- Declaration:
String message;
- String Constant
"Good Morning World!"
- String Assignment
message = "It's Friday";
- String Has Many Methods for Manipulation
- Most important ones are: length(), indexOf(), substring()
-
int length()
-
int indexOf(String st)
-
String substring(int start, int end)
- Getting String Data from the User
- The TextField class has getText() method.
- Can use:
message = mg.getText();
where mg is a TextField and message is a String.
- Exchanging the Contents of Two Variables
- Example Doing Some String Manipulation
StringPlay.java,
StringPlay.html
- Add More Functions
- Last name first format
- All Capitals (
String toUpperCase())