JM-Method
JM-Method
Object-Oriented Programming
and
Data Structures
Maria Litvin
Phillips Academy, Andover, Massachusetts
Gary Litvin
Skylight Software, Inc.
Skylight Publishing
Andover, Massachusetts
Skylight Publishing
9 Bartlet Street, Suite 70
Andover, MA 01810
web: www.skylit.com
e-mail: [email protected]
[email protected]
ISBN 978-0-9972528-2-8
*
AP and Advanced Placement are registered trademarks of The College Board, which was
not involved in the production of and does not endorse this book.
The names of commercially available software and products mentioned in this book are
used for identification purposes only and may be trademarks or registered trademarks
owned by corporations and other commercial entities. Skylight Publishing and the authors
have no affiliation with and disclaim any sponsorship or endorsement by any of these
product manufacturers or trademark owners.
Oracle, Java, and Java logos are trademarks or registered trademarks of Oracle Corporation
and/or its affiliates in the U.S. and other countries.
SCRABBLE® is the registered trademark of HASBRO in the United States and Canada and
of J.W. Spear and Sons, PLC, a subsidiary of Mattel, Inc., outside the United States and
Canada.
1 2 3 4 5 6 7 8 9 10 26 25 24 23 22 21
Preface xiii
How to Use This Book xvii
Chapter 1 Hardware, Software, and the Internet 1
Chapter 2 An Introduction to Software Engineering 11
Chapter 3 Java Syntax and Style 43
Chapter 4 Objects and Classes 65
Chapter 5 Data Types, Variables, and Arithmetic 95
Chapter 6 Boolean Expressions and if-else Statements 133
Chapter 7 Algorithms and Iterations 177
Chapter 8 Strings 207
Chapter 9 Arrays 235
Chapter 10 Implementing and Using Classes 271
Chapter 11 java.util.ArrayList 319
Chapter 12 Class Hierarchies 341
Chapter 13 Algorithms and Recursion 365
Chapter 14 Searching and Sorting 383
Chapter 15 Streams and Files 413
Chapter 16 Graphics 429
Chapter 17 GUI Components and Events 435
Chapter 18 Mouse, Keyboard, Sounds, and Images 443
Chapter 19 Recursion Revisited 447
Chapter 20 Sets and Maps 475
Chapter 21 Computing in Context 495
Appendices
Solutions to Selected Exercises
Index 499
iii
Start
1. Hardware / Software
2. Software Engineering
AP CS A
Exam
3. Syntax and Style
5. Arithmetic
6. Boolean / if-else
Finish
Contents
Preface xiii
v
vi CONTENTS
Appendices