Program Design and Data Structures
ST
5th Edition
UV
SOLUTIONS
IA
MANUAL
?_
AP
John Lewis
PR
Peter DePasquale
Joe Chase
OV
Comprehensive Solutions Manual for Instructors
ED
and Students
© John Lewis, Peter DePasquale & Joe Chase. All rights reserved. Reproduction or
??
distribution without permission is prohibited.
©MEDCONNOISSEUR
, Contents
TU
V
Preface vii
Credits xxix
IA
VideoNotes xxxi
Chapter 1 Introduction 1
1.1 The Java Programming Language 2
?_
A Java Program 3
Comments 5
Identifiers and Reserved Words 7
White Space 9
AP
1.2 Program Development 11
Programming Language Levels 11
Editors, Compilers, and Interpreters 13
Development Environments 15
Syntax and Semantics 16
PR
Errors 17
1.3 Problem Solving 18
1.4 Software Development Activities 20
1.5 Object-Oriented Programming 21
OV
Object-Oriented Software Principles 22
Chapter 2 Data and Expressions 33
2.1 Character Strings 34
The print and println Methods 34
String Concatenation 36
ED
Escape Sequences 40
2.2 Variables and Assignment 41
Variables 41
The Assignment Statement 44
Constants 46
??
xiii
, xiv CONTENTS
TU
2.3 Primitive Data Types 47
Integers and Floating Points 47
Characters 48
Booleans 50
2.4 Expressions 51
Arithmetic Operators 51
V
Operator Precedence 52
Increment and Decrement Operators 56
Assignment Operators 57
IA
2.5 Data Conversion 58
Conversion Techniques 60
2.6 Reading Input Data 61
?_
The Scanner Class 61
Chapter 3 Using Classes and Objects 75
3.1 Creating Objects 76
AP
Aliases 78
3.2 The String Class 80
3.3 Packages 83
The import Declaration 84
PR
3.4 The Random Class 86
3.5 The Math Class 89
3.6 Formatting Output 92
The NumberFormat Class 92
OV
The DecimalFormat Class 94
The printf Method 96
3.7 Enumerated Types 97
3.8 Wrapper Classes 100
Autoboxing 102
ED
Chapter 4 Conditionals and Loops 111
4.1 Boolean Expressions 112
Equality and Relational Operators 113
Logical Operators 114
??
, CONTENTS xv
4.2 The if Statement 116
TU
The if-else Statement 119
Using Block Statements 121
The Conditional Operator 124
Nested if Statements 125
4.3 Comparing Data 127
V
Comparing Floats 127
Comparing Characters 127
Comparing Objects 128
IA
4.4 The switch Statement 130
4.5 The while Statement 134
Infinite Loops 140
?_
Nested Loops 141
Other Loop Controls 144
4.6 Iterators 145
Reading Text Files 146
AP
4.7 The do Statement 148
4.8 The for Statement 151
Iterators and for Loops 156
Comparing Loops 157
PR
Chapter 5 Writing Classes 169
5.1 Classes and Objects Revisited 170
Identifying Classes and Objects 171
Assigning Responsibilities 173
OV
5.2 Anatomy of a Class 173
Instance Data 178
UML Class Diagrams 179
5.3 Encapsulation 181
Visibility Modifiers 182
ED
Accessors and Mutators 183
5.4 Anatomy of a Method 188
The return Statement 194
Parameters 196
Local Data 197
??
Constructors Revisited 198