PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of...

12
PAGES 102-104 Text

Transcript of PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of...

Page 1: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

PAGES 102-104

Text

Page 2: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

Syntax Introduced

char, String

Char is single characterString is a string of characters

How to define them? How to assign them? How to use them?

Page 3: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

Character data type

char letterGrade = ‘A’;char poorGrade = ‘F’;

Usage: if (answer == ‘Y’) { println(“You answered Yes”); }

char letter = ‘a’;// note single quote for charactersfor (int i = 0; i< 26; i++){ println(letter); letter = letter + 1;}

Page 4: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

Words and sentences

String myName; myName = “Bina”;

String firstName = “Bagger”;String lastName = “Vance”;String fullName = firstName + lastName; // here + operator means concatenation

Page 5: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

PAGES 105-106

Type conversion

Page 6: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

Syntax Introduced

Function for conversion: char(), int(), float(), str()

Usage: int i = 65 ; // value of character A char ch1; ch1 = char(i); assigns ch1 = ‘A’ float fNum = 65.3; int j = (int)fNum; // convert floating point number to integer

Page 7: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

PAGES 107-109

Objects: this is a big deal

Page 8: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

What is an object?

Unlike simple/basic data types that have only name and value, objects have name, characteristics, and operations.

You define an object by Its name or id or reference Its characteristics /properties: it has ____, ____ Its operations: It can do _____, _____

Dot notation lets you access the operations of an object as well any publicly accessible characteristics/properties

Page 9: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

Object String

String has a number of chars assigned to it.What are the operations?length() startsWith(char)charAt(int)subString(int)subString(int, int)equals()

Page 10: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

Examples for String Object operations

String s1 = “Player Piano”;int len = s1.length();println(len);

println(s1.startsWith(‘P’));println(s1.startsWith(‘Q’));

char fifth;fifth = s1.charAt(5);

Page 11: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

Examples (contd.)

String s1 = “Mount Vernon”;String s2, s3;s2 = s1.substring(6);s3 = s1.substring(0,5);

println(s1.equals(s1));

Page 12: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.

Text

textSize(32); text("word", 10, 30); fill(0, 102, 153); text("word", 10, 60); fill(0, 102, 153, 51); text("word", 10, 90);