9781111530532 ppt ch07_passing_primitivetypeasobjects

26
Java Programming: From Problem Analysis to Program Design, 5e Chapter 7 Passing Primitive Types as Objects

Upload: terry-yoast

Post on 20-May-2015

364 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: 9781111530532 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 5e

Chapter 7Passing Primitive Types as Objects

Page 2: 9781111530532 ppt ch07_passing_primitivetypeasobjects

2

• Java provides the classes Integer, Double, Character, Long, and Float so that the values of the primitive data types can be treated as objects

• These classes have limitations

• You can create objects of the type, say Integer, to store int values, but you cannot change the values stored in the objects

• You can create objects of type IntClass and/or change the values of the objects

Java Programming: From Problem Analysis to Program Design, 5e

Page 3: 9781111530532 ppt ch07_passing_primitivetypeasobjects

3Java Programming: From Problem Analysis to Program Design, 5e

Page 4: 9781111530532 ppt ch07_passing_primitivetypeasobjects

4Java Programming: From Problem Analysis to Program Design, 5e

Page 5: 9781111530532 ppt ch07_passing_primitivetypeasobjects

5Java Programming: From Problem Analysis to Program Design, 5e

Page 6: 9781111530532 ppt ch07_passing_primitivetypeasobjects

6Java Programming: From Problem Analysis to Program Design, 5e

Page 7: 9781111530532 ppt ch07_passing_primitivetypeasobjects

7Java Programming: From Problem Analysis to Program Design, 5e

Page 8: 9781111530532 ppt ch07_passing_primitivetypeasobjects

8Java Programming: From Problem Analysis to Program Design, 5e

Sample Run: In this sample run, the user input is shadedLine 1: Based on the course score, this program computes the course grade.Line 5: Enter the course score: 90.50Line 9: The course score is 90.5Line 10: Your grade for the course is A

Page 9: 9781111530532 ppt ch07_passing_primitivetypeasobjects

9Java Programming: From Problem Analysis to Program Design, 5e

Page 10: 9781111530532 ppt ch07_passing_primitivetypeasobjects

10Java Programming: From Problem Analysis to Program Design, 5e

Page 11: 9781111530532 ppt ch07_passing_primitivetypeasobjects

11Java Programming: From Problem Analysis to Program Design, 5e

Page 12: 9781111530532 ppt ch07_passing_primitivetypeasobjects

12Java Programming: From Problem Analysis to Program Design, 5e

Page 13: 9781111530532 ppt ch07_passing_primitivetypeasobjects

13Java Programming: From Problem Analysis to Program Design, 5e

Page 14: 9781111530532 ppt ch07_passing_primitivetypeasobjects

14Java Programming: From Problem Analysis to Program Design, 5e

Page 15: 9781111530532 ppt ch07_passing_primitivetypeasobjects

15Java Programming: From Problem Analysis to Program Design, 5e

num1 = 10; //Line 5

Page 16: 9781111530532 ppt ch07_passing_primitivetypeasobjects

16Java Programming: From Problem Analysis to Program Design, 5e

num1 = 10; //Line 5num2.setNum(15); //Line 6ch = 'A'; //Line 7str = new StringBuffer("Sunny"); //Line 8

Page 17: 9781111530532 ppt ch07_passing_primitivetypeasobjects

17Java Programming: From Problem Analysis to Program Design, 5e

Page 18: 9781111530532 ppt ch07_passing_primitivetypeasobjects

18Java Programming: From Problem Analysis to Program Design, 5e

num = b.getNum(); //Line 14

Page 19: 9781111530532 ppt ch07_passing_primitivetypeasobjects

19Java Programming: From Problem Analysis to Program Design, 5e

Page 20: 9781111530532 ppt ch07_passing_primitivetypeasobjects

20Java Programming: From Problem Analysis to Program Design, 5e

Page 21: 9781111530532 ppt ch07_passing_primitivetypeasobjects

21Java Programming: From Problem Analysis to Program Design, 5e

Page 22: 9781111530532 ppt ch07_passing_primitivetypeasobjects

22Java Programming: From Problem Analysis to Program Design, 5e

Page 23: 9781111530532 ppt ch07_passing_primitivetypeasobjects

23Java Programming: From Problem Analysis to Program Design, 5e

Page 24: 9781111530532 ppt ch07_passing_primitivetypeasobjects

24Java Programming: From Problem Analysis to Program Design, 5e

Page 25: 9781111530532 ppt ch07_passing_primitivetypeasobjects

25Java Programming: From Problem Analysis to Program Design, 5e

Page 26: 9781111530532 ppt ch07_passing_primitivetypeasobjects

26Java Programming: From Problem Analysis to Program Design, 5e