2nd Edition
Introduction to Programming and Problem-Solving Using Scala
Praise for the first edition:
"The well-written, comprehensive book…[is] aiming to become a de facto reference for the language and its features and capabilities. The pace is appropriate for beginners; programming concepts are introduced progressively through a range of examples and then used as tools for building applications in various domains, including sophisticated data structures and algorithms…Highly recommended. Students of all levels, faculty, and professionals/practitioners.—D. Papamichail, University of Miami in CHOICE Magazine
Mark Lewis’ Introduction to the Art of Programming Using Scala was the first textbook to use Scala for introductory CS courses. Fully revised and expanded, the new edition of this popular text has been divided into two books. Introduction to Programming and Problem-Solving Using Scala is designed to be used in first semester college classrooms to teach students beginning programming with Scala. The book focuses on the key topics students need to know in an introductory course, while also highlighting the features that make Scala a great programming language to learn.
The book is filled with end-of-chapter projects and exercises, and the authors have also posted a number of different supplements on the book website. Video lectures for each chapter in the book are also available on YouTube. The videos show construction of code from the ground up and this type of "live coding" is invaluable for learning to program, as it allows students into the mind of a more experienced programmer, where they can see the thought processes associated with the development of the code.
About the Authors
Mark Lewis is a Professor at Trinity University. He teaches a number of different courses, spanning from first semester introductory courses to advanced seminars. His research interests included simulations and modeling, programming languages, and numerical modeling of rings around planets with nearby moons.
Lisa Lacher is an Assistant Professor at the University of Houston, Clear Lake with over 25 years of professional software development experience. She teaches a number of different courses spanning from first semester introductory courses to graduate level courses. Her research interests include Computer Science Education, Agile Software Development, Human Computer Interaction and Usability Engineering, as well as Measurement and Empirical Software Engineering.
Basics of Computers, Computing, and Programming
History
Hardware
Central Processing Unit
Memory
Input/Output Devices
Software
Nature of Programming
Programming Paradigms
Imperative Programming
Functional Programming
Object-Oriented Programming
Logic Programming
Nature of Scala
End of Chapter Material
Summary of Concepts
Exercises
Projects
Scala Basics
Scala Tools
Expressions, Types, and Basic Math
Objects and Methods
Other Basic Types
Back to the Numbers
Binary Arithmetic
Negative Numbers in Binary
Other Integer Types
Octal and Hexadecimal
Non-Integer Numbers
The math Object
Naming Values and Variables
Patterns in Declarations
Using Variables
Details of Char and String
Escape Characters
Raw Strings
String Interpolation
String Methods
Immutability of Strings
Sequential Execution
Comments
A Tip for Learning to Program
End of Chapter Material
Problem Solving Approach
Summary of Concepts
Self-Directed Study
Exercises
Conditionals
Motivating Example
The if Expression
Comparisons
Boolean Logic
Precedence
Nesting ifs
Bit-Wise Arithmetic
End of Chapter Material
Problem Solving Approach
Summary of Concepts
Self-Directed Study
Exercises
Projects
Functions
Motivating Example
Function Refresher
Making and Using Functions
Problem Decomposition
Function Literals/Lambda Expressions/Closure
Side Effects
Thinking about Function Execution
type Declarations
Putting It Together
End of Chapter Material
Problem Solving Approach
Summary of Concepts
Self-Directed Study
Exercises
Projects
Recursion for Iteration
Basics of Recursion
Writing Recursive Functions
User Input
Abstraction
Matching
Bad Input, Exceptions, and the try/catch Expression
Putting It Together
Looking Ahead
End of Chapter Material
Problem Solving Approach
Summary of Concepts
Self-Directed Study
Exercises
Projects
Arrays and Lists in Scala
Making Arrays
Using Arrays
Lists
Bigger Arrays and Lists with Fill and Tabulate
Standard Methods
Basic Methods
Higher-Order Methods
reduce and fold
Combinatorial/Iterator Methods
Complete Grades Script/Software Development
Playing with Data
Reading the Data
Finding Maximum Values
End of Chapter Material
Problem Solving Approach
Summary of Concepts
Self-Directed Study
Exercises
Projects
Type Basics and Argument Passing
Scala API
The Option Type
Parametric Functions
Subtyping
Variable Length Argument Lists
Mutability and Aliasing
Basic Argument Passing
Currying
Pass-By-Name
Multidimensional Arrays
Classifying Bugs
End of Chapter Material
Problem Solving Approach
Summary of Concepts
Self-Directed Study
Exercises
Projects
Loops
while Loop
do-while Loop
for Loop
Range Type
yield
if Guards
Multiple Generators
Patterns in for Loops
Variable Declarations
Multidimensional Sequences and for Loops
Testing
Putting It Together
End of Chapter Material
Problem Solving Approach
Summary of Concepts
Self-Directed Study
Exercises
Projects
Text Files
I/O Redirection
Packages and import Statements
Reading from Files
Iterators
String split Method
Reading from Other Things
Other Options (Java Based)
Writing to File
Appending to File
Use Case: Simple Encryption
Command Line Arguments
Mapping a File
Character Offset
Alphabet Flip
Key Word
Putting It Together
Primes and Real Cryptography
End of Chapter Material
Summary of Concepts
Self-Directed Study
Exercises
Projects
Case Classes
User Defined Types
case classes
Making Objects
Accessing Members
Named and Default Arguments (Advanced)
The copy Method
case class Patterns
Mutable classes
Putting It Together
End of Chapter Material
Summary of Concepts
Self-Directed Study
Exercises
Projects
GUIs
GUI Libraries and History
First Steps
Stages and Scenes
Events and Handlers
Controls
Text Controls
Button-like Controls
Selection Controls
Pickers
TableView
TreeView
Menus and FileChooser
Other Stuff
Observables, Properties, and Bindings
Numeric Properties and Bindings
Conditional Bindings
Layout and Panes
scalafx.scene.layout Panes
scalafx.scene.control Panes
Putting It Together
End of Chapter Material
Summary of Concepts
Self-Directed Study
Exercises
Projects
Graphics and Advanced ScalaFX
Shapes
Path Elements
Paint and Stroke
Basic Keyboard, Mouse, and Touch Input
Images
Writing Images to File
Transformations
Animation
Transitions
Timelines
AnimationTimer
Canvas
Settings
Basic Fills and Strokes
Building a Path
Image Operations on Canvas
A Canvas Based Game
Effects
Charts
Media
Web
3D Graphics
Putting It Together
End of Chapter Material
Summary of Concepts
Exercises
Projects
Sorting and Searching
Basic Comparison Sorts
Bubble Sort
Selection Sort (Min/Max Sort)
Insertion Sort
Testing and Verifying Sorts
Sort Visualization
Order Analysis
Shell Sort (Diminishing Gap Sort)
Searching
Sequential Search (Linear Search)
Binary Search
Sorting/Searching with case classes
Sorting Lists
Performance and Timing
Putting It Together
End of Chapter Material
Summary of Concepts
Exercises
Projects
XML
Description of XML
Tags
Elements
Attributes
Content
Special Characters
Comments
Overall Format
Comparison to Flat File
Flexibility in XML
XML in Scala
Loading XML
Parsing XML
Building XML
Writing XML to File
XML Patterns
Putting It Together
End of Chapter Material
Summary of Concepts
Self-Directed Study
Exercises
Projects
Recursion
Memory Layout
Power of Recursion
Fibonacci Numbers
Towers of Hanoi
Permutations
Mazes
Sorts
Divide and Conquer Sorts
Merge Sort
Quicksort
Putting It Together
End of Chapter Material
Summary of Concepts
Exercises
Projects
Object-Orientation
Basics of Object-Orientation
Analysis and Design of a Bank
Analysis and Design of Pac-Man™
Implementing OO in Scala
Methods and Members
Parameters as Members
Visibility
Special Methods
Property Assignment Methods
The apply Method
this Keyword
object Declarations
Applications
Introduction to Companion Objects
Revisiting the API
Implementing the Bank Example
Implementing the Pac-Man™ Example
End of Chapter Material
Summary of Concepts
Exercises
Projects
Wrapping Up
What You Have Learned
IDEs (Eclipse)
Next Steps
End of Chapter Material
Exercises
Appendix A Getting to Know the Tools
Unix/Linux (includes Mac OS X)
Command Line
Files and Directories
Aside
Helpful Tips
Permissions
Compression/Archiving
Remote
Other Commands
Redirection
Text Editors (vi/vim)
Windows
Command Line
Files and Directories
Text Editors
Edit
Notepad
Others
Other Commands
End of Appendix Material
Summary of Concepts
Exercises
B Glossary
Bibliography
Biography
Mark Lewis is an Associate Professor in the Department of Computer Science at Trinity University. He teaches a number of different courses, spanning from first semester introductory courses to advanced seminars. He also has research interests in a number of different areas including simulations and modeling and programming languages. He is also the coach for Trinity's ACM programming teams