|
home—info—lects—labs—exams—hws
textbook—tutor/PIs—java.lang docs—java.util docs
Quick review:
int fps; // Number of frames-per-second. fps = 24; // 24 would be movie; 30 would be TV. |
object-dot-methodname-openParen-arguments-closeParen.E.g.,
raki.ufoHeight( 5*fps ) // Assuming 'raki' is a RocketScientist (lect01a) Math.sqrt(24.9) System.out.print( 3+4 ); |
Suppose we work for Olympic swimming, and want to track the results for an race entrant:
Example: Example: Michael Phelps, in lane 4, swam in 49.27 seconds.
Today we'll discuss and practice:
Write a program which will print the message:
Never speak the word "ineffable" again! ...Instead we'll just say "ie". |
We'll use the String method charAt to extra individual characters from a String.
Java trivia: Minor note: We use the escape code \" to embed a quotation-mark in the middle of a string:The only other escape code I find myself using often is a newline character, \n. You can see 'advanced tip 4.4' in the book, for more escape codes.
System.out.println( "She says \"hello\" to you." );
Java trivia: The java method Character.toString(char) converts individual characters into Strings. For example, Character.toString('m') returns "m".
(Notice the single-quote vs. double-quote difference between characters and Strings, in Java.)
Reading input: If you want to prompt the user for an input, you can use the Java method javax.swing.JOptionPane.showInputDialog(String). For example:
javax.swing.JOptionPane.showInputDialog("What is your quest?") |
String job; job = javax.swing.JOptionPane.showInputDialog("What is your quest?"); |
Java library trivia: You can use print a message with a corresponding method showMessageDialog. This method requires two inputs, the first of which is always null1.
Java trivia: If you want to save some typing, it's possible to write import javax.swing.JOptionPane; at the top of your program. Then, in your program, you can just say JOptionPane and java will know the full-name you are referring to.There is nothing mysterious about import — it saves you a bit of typing, that's all.
1We won't talk about null in this class: the only way it arises is if you forget to initialize a field. ↩
home—info—lects—labs—exams—hws
textbook—tutor/PIs—java.lang docs—java.util docs
©2009, Ian Barland, Radford University Last modified 2009.Jan.30 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |