Announcements Review Announcements Friday Im away Katie Coons
- Slides: 19
Announcements & Review Announcements Friday I’m away, Katie Coons will teach Last Time: – – int, boolean some operations boolean logic if-then-else! Lab 1 Due Thursday 10 pm Use turnin 1 file per pair Lecture 6: String Objects and Input
Today Clairfy float verses double Finish if-then-else example More basic program elements Objects versus values Strings & their operators Input Using the Scanner class Lecture 6: String Objects and Input
Values versus objects • Numbers – Have values but they do not have behaviors • Objects – Have attributes and behaviors • System. out - References an Output. Stream – Attribute: monitor – Behaviors: printing • System. in: References an Input. Stream – Attribute: keyboard – Behaviors: reading Lecture 6: String Objects and Input
String Objects • Consider String a = "excellence"; String b = a; • What is the representation? Lecture 6: String Objects and Input
Examples • Consider String a = "excellence"; String b = a; • What is the representation? a "excellence" b Lecture 6: String Objects and Input
Uninitialized versus null • Consider String day. Of. Week; Scanner in. Stream; • What is the representation? Lecture 6: String Objects and Input
Uninitialized versus null • Consider String day. Of. Week; Scanner in. Stream; • What is the representation? day. Of. Week - in. Stream - Lecture 6: String Objects and Input
Uninitialized versus null • Consider String font. Name = null; Scanner file. Stream = null; • What is the representation? Lecture 6: String Objects and Input
Uninitialized versus null • Consider String font. Name = null; Scanner file. Stream = null; • What is the representation? font. Name null file. Stream null Lecture 6: String Objects and Input
Assignment • Consider String word 1 = "luminous"; String word 2 = "graceful"; -> word 1 = word 2; • Representation at -> word 1 "luminous" word 2 "graceful" Lecture 6: String Objects and Input
Assignment • Consider String word 1 = "luminous"; String word 2 = "graceful"; word 1 = word 2; -> • After assignment word 1 word 2 "graceful" Lecture 6: String Objects and Input
String representation • Consider – String alphabet = "abcdefghijklmnopqrstuvwxyz"; • Standard shorthand representation "abcdefghijklmnopqrstuvwxyz" alphabet • Truer representation alphabet a b c d e f g h i j k l m n o p q Lecture 6: String Objects and Input r s t u v w y z
Some String Methods // a string objects String alphabet = "abcdefghijklmnopqrstuvwxyz"; // operations on string objects char c 1 = alphabet. char. At(9); int position = alphabet. index. Of(“e”); String ab = alphabet. substring(0, 2); String more. Letters = ab. concat(alphabet); boolean same. Str = more. Letters. equals(ab); …. lots more … see pgs 877 --882 in Cohoon & Davidson or Javadoc (google it!) Lecture 6: String Objects and Input
Example String Method String alphabet = "abcdefghijklmnopqrstuvwxyz"; char c 1 = alphabet. char. At(9); char c 2 = alphabet. char. At(2); int i 1 = alphabet. index. Of(“de”); • What are the values of c 1, c 2, and c 3? Why? Lecture 6: String Objects and Input
Blue. J Examples Lecture 6: String Objects and Input
Reading Input Features // Scanner is an “extra” Java class, so we // need to tell the compiler where to find it import java. util. * // allocates an object of class Scanner stdin = new Scanner(System. in); String name = stdin. next(); int age = stdin. next. Int(); double commute. Distance = stdin. next. Double(); boolean parent = stdin. next. Boolean(); // peeking to make sure the format is right // -- we will use these in Lecture 8 boolean is. String = stdin. has. Next(); boolean is. Int = stdin. has. Next. Int(); boolean is. Double = stdin. has. Next. Double(); boolean is. Boolean = stdin. has. Next. Boolean(); Lecture 6: String Objects and Input
Reading Input Example // Scanner is an “extra” Java class, so we // need to tell the compiler where to find it import java. util. * // allocates an object of class Scanner stdin = new Scanner(System. in); System. out. print("Enter a word: "); String word = stdin. next(); int word. Length = word. length(); System. out. println("Word " + word + " has length ” + word. Length + ". "); Lecture 6: String Objects and Input
Blue. J Examples Lecture 6: String Objects and Input
More Questions? Lecture 6: String Objects and Input
- Coons patch
- Senator chris coons
- Go away scary monster go away
- Fahrenheit 451 burning bright summary
- Pvu announcements
- Potentiial
- R/announcements!
- General announcements
- David ritthaler
- Aldin hadzic
- Katie bouman nobel prize
- Carly lockwood
- Katie schoultz
- Katie halvorson
- Katie's trunk by ann turner
- Leslie bromberg
- Katie colpitts
- Katie be
- Katie fazio
- Katie morag characters