Download Object-Oriented Programming - HWS Department of Mathematics

Transcript
6.7 Basic Layout . . . . . . . . . . .
6.7.1 Basic Layout Managers
6.7.2 A Simple Calculator . .
6.7.3 A Little Card Game . . .
6.8 Images and Resources . . . . .
6.8.1 Images . . . . . . . . . .
6.8.2 Image File I/O . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
143
144
146
148
152
153
155
7 A Solitaire Game - Klondike
7.1 Klondike Solitaire . . . . . . . . . . . . . .
7.2 Card Games . . . . . . . . . . . . . . . . .
7.2.1 The CardNames Interface . . . . .
7.2.2 The Deck class . . . . . . . . . . . .
7.3 Implementation of Klondike . . . . . . . .
7.3.1 The CardPile class (the base class)
7.3.2 The Solitaire class . . . . . . . . . .
7.3.3 Completing the Implementation .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
157
. 157
. 158
. 160
. 160
. 160
. 161
. 163
. 164
8 Generic Programming
8.1 Generic Programming in Java .
8.2 ArrayLists . . . . . . . . . . . .
8.3 Parameterized Types . . . . . .
8.4 The Java Collection Framework
8.5 Iterators and for-each Loops . .
8.6 Equality and Comparison . . .
8.7 Generics and Wrapper Classes
8.8 Lists . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
167
168
168
170
172
174
176
179
179
9 Correctness and Robustness
9.1 Introduction . . . . . . . . . . . . . . . . .
9.1.1 Horror Stories . . . . . . . . . . . .
9.1.2 Java to the Rescue . . . . . . . . .
9.1.3 Problems Remain in Java . . . . .
9.2 Writing Correct Programs . . . . . . . . .
9.2.1 Provably Correct Programs . . . .
9.2.2 Robust Handling of Input . . . . .
9.3 Exceptions and try..catch . . . . . . . . . .
9.3.1 Exceptions and Exception Classes
9.3.2 The try Statement . . . . . . . . . .
9.3.3 Throwing Exceptions . . . . . . . .
9.3.4 Mandatory Exception Handling . .
9.3.5 Programming with Exceptions . .
9.4 Assertions . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
185
. 186
. 186
. 187
. 189
. 190
. 190
. 193
. 194
. 194
. 196
. 199
. 200
. 201
. 203
10 Input and Output
10.1 Streams, Readers, and Writers . . .
10.1.1 Character and Byte Streams
10.1.2 PrintWriter . . . . . . . . . .
10.1.3 Data Streams . . . . . . . . .
10.1.4 Reading Text . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
7
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
207
207
207
209
210
211