Dale, Joyce and Weems 2nd edition - Classes

Compiled by Nicholas Duchon

Date: Nov 13, 2006

Chapter 1

Pg
Class - *=interface
Methods Vars *=static
Notes
11
Date
Date (int, int, int)
getYear (): int
getMonth(): int
getDay(): int
lilian (): int
toString(): String
int year
int month
int day
int MINYEAR
-
19
DaysBetween
main
-
exercise Date
22
IncDate x Date
IncDate (int, int, int)
increment (): void
-
-

Chapter 2

Pg
Class - *=interface
Methods Vars *=static
Notes
67
FigureGeometry *
perimeter (): float
area (): float
setScale (int): void
wieght (): void
PI *
use Math.PI instead
68
Circle i FigureGeometry
Circle (float)
float radius
int scale
plus interface methods
72
StringLogInterface
insert (String): void
isFull (): boolean
size (): int
contains (String): boolean
clear (): void
getName (): String
toString (): String
-
toString should not be here

73
UseStringLog
main

uses ArrayStringLog
83
ArrayStringLog i StringLogInterface
ArrayStringLog (String, int)
ArrayStringLog (String)
String name
String [] log
int lastIndex
contains ignores case
94
ITDArrayStringLog
main

Interactive Test Driver
104
LLStringNode
LLStringNode (String)
setInfo (String): void
getInfo (): String
setLink (LLStringNode): void
getLink (): LLStringNode
String info
LLStringNode link
A node in a linked list
120
LinkedStringLog i StringLogInterface
LinkedStringLog (String) LLStringNode log
String name

132
TriviaQuestion
TriviaQuestion (String, String, int)
getCategory (): String
getQuestion (): String
tryAnswer (String): boolean
storeAnswer (String): void
String category
String question
StringLogInterface answers
instantiates ArrayStringLog
134
TriviaGame
TriviaGame (String, int, int)
getQuizName (): String
getNumChances (): int
getRemainingChances (): int
getNumCorrect (): int
getNumIncorrect (): int
getCurrentNumQuestions (): int
getTriviaQuestion (int): TriviaQuestion
isAnswered (int): boolean
isOver (): boolean
insertQuestion (TriviaQuestion): void
correctAnswer (int): void
incorrectAnswer (): void
String quizName
int maxNumQuestions
int numChances
int remainingChances
int numCorrect
int numIncorrect
TriviaQuestion [] questions
boolean [] correct
int currentNumQuestions
Too many trivial methods!
137
GetTriviaGame
useTextFile (String): TriviaGame

reads questions from a text file
so why a new class?
140
TriviaConsole
main

text interface to TriviaGame

Chapter 3

Pg
Class - *=interface
Methods Vars *=static
Notes
165
Date


as in chapter 1
166
DateOutOfBoundsException x Exception


should be more careful about what is extended
167
UseDates
main

template test harness, perhaps ITD?
173
StackUnderflowException x RuntimeException
StackUnderflowException ()
StackUnderflowException (String)

Not checked by compiler
174
StackOverflowException x RuntimeException
StackOverflowException ()
StackOverflowException (String)

Not checked
175
* StackInterface
pop (): void
top (): Object
isEmpty (): boolean

push??
177
* BoundedStackInterface x StackInterface
push (Object): void
isFull (): boolean


177
* UnboundedStackInterface x StackInterface
push (Object): void

what's the point?
183
Balanced
Balanced (String, String)
test (String): int
String openSet
String claseSet

186
BalancedApp
main

ITD?
189
ArrayStack i BoundedStackInterface
ArrayStack ()
ArrayStack (int)
int DEFCAP
Object [] stack
int topIndex
Array implementation of a Stack
194
ArrayListStack i UnboundedStackInterface

ArrayList<Object> stack
uses the generic Collections class ArrayList
196
LLObjectNode
LLObjectNode (Object)
setInfo (Object): void
getInfo (): void
setLink (LLObjectNode): void
getLink (): LLObjectNode
LLObjectNode link
Object info
A node in a linked structure
198
LinkedStack i UnboundedStackInterface
LinkedStack ()
LLObjectNode top
methods spread over section
216
PostFixEvaluator
evaluate (String): int

uses a stack (LIFO) algorithm
218
PFixConsole
main

ITD for previous
222
PFixGUI
?
?
just a balloon and pictures

Chapter 4

Pg
Class - *=interface
Methods Vars *=static
Notes
250
Towers
main
doTowers (int, int, int, int)
String indent
Solution to Towers of Hanoi
257
Grid
Grid (nt, int, int)
toString (): String
blobCount (): int
markBlob (int, int): void
int rows
int cols
boolean [][] grid
boolean [][] visited
counts blobs using a recursive marking scheme
260
BlopApp
main

ITD for Grid
264
LinkedStack2 x LinkedStack
revPrint (LLObjectNode): void
printReversed (): void

see pg 198
266
Kids
countKids (int, int): int
main

adds 2 ints !?!?!
268
ActivationRecordType

AddressType returnAddr
int result
int n
A possibility
272
LinkedStack3 x LinkedStack
printReversed (): void]


Chapter 5

Error in drawing on pg 348:
Pg
Class - *=interface
Methods Vars *=static
Notes
293
QueueInterface *
dequeue (): Object + E
isEmpty (): boolean

underflow exception
294
BoundedQueueInterface * x QueueInterface
enqueue (Object): void + E
isFull (): boolean

overflow exception
294
UnboundedQueueInterface * x QueueInterface
enqueue (Object): void

no exception
295 (?)
QueueUnderflowException
QueueUnderflowException ()
QueueUnderflowException (String)

drawing on pg 295
295 (?)
QueueOverflowException
QueueOverflowException ()
QueueOverflowException (String)

drawing on pg 295
297
Palindrome
test (String): boolean

an application of queues and stacks
299
PalindromeApp
main

test test?
305
ArrayBndQueue i BoundedQueueInterface
ArrayBndQueue
ArrayBndQueue (int)
int DEFCAP
Object [] queue
int numElements
int front
int rear
Introduces a circular/ring buffer
309
ArrayUnbndQueue i UnboundedQueueInterface
ArrayUnbndQueue ()
ArrayUnbndQueue (int)
enlarge (): void
int defCap
Object [] queue
int origCap
int numElements
int front
int rear
auto enlarging, should double size.
protocol: copies object reference
312
RankCardDeck
RankCardDeck ()
shuffle (): void
hasMoreCards (): boolean
nextCard (): int
int numCards
int [] cardDeck
int curCardPos
Random rn
Deck of cards for War game
315
WarGame
WarGame (int)
getNumBattles (): int
play(): boolean
battle (): void
BoundedQueueInterface player1
BoundedQueueInterface player2
int maxNumBattles
RankCardDeck deck
BoundedQueueInterface prize
int numCards

318
WarGameApp
main

user interface to game
322  &
326
LinkedUnbndQueue i UnboundedQueueInterface
LinkedUnbndQueue ()

LLObjectNode front
LLObjectNode rear
complete version on 326-327
LLObjectNode on pg 196
337
Customer
Customer (int, int)
getArrivalTime (): int
getServiceTime (): int
setFinishTime (int): void
getFinishTime (): int
getWaitTime (): int
int arrivalTime
int serviceTime
int finishTime
a customer in a queue simulation
339
CustomerGenerator
int minIAT
int maxIAT
int minST
int maxST
int curTime
Random rn
CustomerGenerator (int, int, int, int)
nextCustomer (): Customer

340
GlassQueue x ArrayUnbndQueue
GlassQueue ()
GlassQueue (int)
size (): int
peekFront (): Object
peekRear (): Object

Real applications require more than theoretical methods
341
Simulation
Simulation (int, int, int, int)
getAvgWaitTime (): float
simulate (int, int): void
int MAXTIME
CustomerGenerator custGen
float avgWaitTime
simulate is one long method
float --> double
344
SimulationApp
main

The driver for the application.

Chapter 6

Pg
Class - *=interface
Methods Vars *=static
Notes
361
Circle i Comparable
Circle (float)
equals (Circle): boolean
compareTo (Object): int
perimeter (): float
area (): float
float radius
float PI
use Math.PI
use double
366
ListInterface *
size (): int
contains (Object): boolean
remove (Object): boolean
get (Object): Object
toString (): String
reset (): void
getNext (): Object

No add!?!?!?
368
UnsortedListInterface x ListInterface
add (Object): void


368
SortesListInterface x ListInterface
add (Comparable): void


369
IndexedListInterface x ListInterface
add (int, Object): void
set (int, Object): Object
get (int): Object
indexOf (Object): int
remove (int): Object


376
List
List ()
List (int)
enlarge (); void
find (Object): void
size (): int
contains (Object): boolean
remove (Object): boolean
get (Object): Object
toString (): String
reset (): void
getNext (): Object
int DEFCAP
int origCap
Object [] list
int numElements
int currentPos
boolean found
int location
so what were all the interfaces for?
381
ArrayUnsortedList x List i UnsortedListInterface
ArrayUnsortedList ()
ArrayUnsortedList (int)
add (Object): void
remove (Object): boolean

So?
384
ArraySortedList x List i SortedListInterface
ArraySortedList ()
ArraySortedList (int)
add (Comparable): void


390
ArrayIndexedList x List i IndexedListInterface
ArrayIndexedList ()
ArrayIndexedList (int)
add (int, Object): void
set (int, Object): Object
get (int): Object
indexOf (Object): int
remove (int): Object
toString (): String

methods to handle a List a certain way.
396
PokerApp
main

uses RankCardDeck, pg 312
ArrayUnsortedList, pg 381
398
Golfer i Comparable
Golfer (String)
getName (): String
getScore (): int
compareTo (Object): int
toString (): String
String name
int score

399
GolfApp
main

uses ArraySortedList
401
Song
Song (String, int)
Song (String, int, int)
getName (): String
getDuration (): int
toString (): String


402
SongApp
main

uses ArrayIndexedList
377
407
412
416
416

find (Object): void
find (Object): void
recFind (Object, int, int): void
find (Object): void
find (Object): void

List, linear
uses Comparable and indexed list, binary search
Comparable and indexed list, recursive binary search
indexed, linear
linked list, linear
411
ArraySortedList2


??? in Figure.
418
RefList
RefList ()
find (Object): void
size (): int
contains (Object): boolean
remove (Object): boolean
get (Object): Object
toString (): String
reset (): void
getNext (): Object
int numElements
LLObjectNode currentPos
boolean found
LLObjectNode location
LLObjectNode previous
LLObjectNode list
extends, implements??
421
RefUnsortedList x RefList i UnsortedListInterface
RefUnsortedList ()
add (Object): void


425
RefSortedList x RefList i SortedListInterface
RefSortedList ()
add (Comparable): void


428
SaveSong
main
PrintWriter outFile

429
GetSong
main

Use File instead of FileReader
430
SerSong
SerSong (String, int)
SerSong (String, int, int)
getName (): String
getDuraction (): int
toString (): String
String name
int duration
DecimalFormat fmt

431
SaveSerSong
main
PrintWriter outFile
uses ObjectOutputStream. FileOutPutStream and writeObject
432
GetSerSong
main

uses ObjectInputStream, FileInputStream and readObject
435
SerSongList
SerSongList (String)
getListName (): String
getTotDuration (): int
getSize (): int
add (int, SerSong): void
toString (): String
String listName
int totDuration
SArrayIndexedList songList
DecimalFormat fmt


ArraySortedList2 ??
437
SerSongApp
main

one long main!

Chapter 7

Pg
Class - *=interface
Pg
Methods Vars *=static
Notes
458
CRefList

461
459
462
462
462
460
459
459
CRefList ()
find (Object): void
size (): int
contains (Object): boolean
remove (Object): boolean
get (Object): Object
toString (): String
reset (): void
getNext (): Object
LLObjectNode list
int numElements
boolean found
LLObjectNode location
LLObjectNode previous
LLObjectNode currentPos
reset () and  getNext () changed from RefList (pg 418)
458
CRefUnsortedList x CRefList
465
465
CRefUnsortedList ()
add (Object): void

constructor is trivial, why bother?
467
DLLObjectNode x LLObjectNode
467
467
468
DLLObjectNode (Object)
setBack (DLLObjectNode): void
getBack (): DLLObjectNode

doubly linked list
477
ArrayRefSortedList i SortedListInterface
478
478
479
480
480

ArrayRefSortedList (int)
getNode (): int
freeNode (int): void
isFull (): boolean
remove (Object): boolean

AListNode [] nodes
int list
int free
int numElements
int currentPos
boolean found
int location
int previous
Array based sorted list using indices for positions
477
AListNode


Object info
int next
inner class of ArrayRefSortedList
481
SpecializedListInterface *
482
resetForward (): void
getNextElement (): byte
resetBackward (): void
gerPriorElement (): byte
size (): int
addFront (byte): void
addEnd (byte): void

Used in example in section 7.6, pp 487-506
byte???
483
SpecializedList i SpecializedListInterface
484
484
484
484
485
485
485
487
SpecializedList ()
size (): int
resetForward (): void
getNextElement (): byte
resetBackward (): void
getPriorElement (): byte
addFront (byte): void
addEnd (byte): void
SListNode listFirst
SListNode listLast
int numElements
SListNode currentFPos
SListNode currentBPos
end of class not indicated on pg 487
483
SListNode


byte info
SListNode next
SListNode back
inner class for SpecializedList
491
LargeInt
491
491
492
492
493
494
496
498
500
501
LargeInt ()
LargeInt (String)
getNegative (): void
addDigit (byte): void
toString (): String
greaterList (SpecializedList, SpecializedList): boolean
addLists (SpecializedList, SpecializedList): SpecializedList
subtractLists (SpecializedList, SpecializedList): SpecializedList
add (LargeInt, LargeInt): LargeInt
subtract (LargeInt, LargeInt): LargeInt
SpecializedList numbers
boolean sign





class should implement Comparable, and this should be compareTo - the add and subtract lists methods probably should not even exist.

add and subtract should be instance, not static, methods

class ends on pg 501 without final brace
502
LargeIntApp
502
main


Chapter 8

Pg
Class - *=interface
Pg
Methods Vars *=static
Notes
526
BSTInterface *

isEmpty (): boolean
size (): int
contains (Comparable): boolean
remove (Comparable): boolean
get (Comparable): Comparable
add (Comparable): void
reset (int): int
getNext (int): Comparable


528
GolfApp2

main

uses BinarySearchTree - pg 531
530
BSTNode

BSTNode (Comparable)
setInfo (Comparable): void
getInfo (): Comparable
setLeft (BSTNode): void
setRight (BSTNode): void
getLeft (): BSTNode
getRight (): BSTNode
Comparable info
BSTNode left
BSTNode right

531
BinarySearchTree i BSTInterface
532
532
533
536
538
540
540
542
542
544
546
548
553
553
554
556
557
558
559
559
BinarySearchTree ()
isEmpty (): boolean
size (): int
recSize (BSTNode): int
size (): int (version 2)
recContains (Comparable, BSTNode): boolean
contains (Comparable): boolean
recGet (Comparable, BSTNode): Comparable
get (Comparable): Comparable
add (Comparable): void
recAdd (Comparable, BSTNode): BSTNode
remove (Comparable): boolean
recRemove (Comparable, BSTNode): BSTNode
removeNode (BSTNode): BSTNode
getPredecessor (BSTNode): Comparable
reset (int): int
getNext (int): Comparable
inOrder (BSTNode): void
preOrder (BSTNode): void
postOrder (BSTNode): void
BSTNode root
boolean found
ArrayBndQueue inOrderQueue
ArrayBndQueue preOrderQueue
ArrayBndQueue postOrderQueue
Class ends on pg 559 without a brace.
577
WordFreq i Comparable
577
WordFreq (String)
inc (): void
compareTo (Object): int
toString (): String
wordIs (): String
freqIs (): int
String word
int freq
DecimalFormat fmt
fmt should be static
578
FrequencyList

main

uses WordFreq and Binary SearchTree

Chapter 9

Pg
Class - *=interface
Pg
Methods Vars *=static
Notes
599
PriQueueInterface *

isEmpty (): boolean
isFull (): boolean
enqueue (Comparable): void
dequeue (): Comparable


599
PriQUnderflowException x RuntimeException

PriQUnderflowException ()
PriQUnderflowException (String)

why bother with constructors?
not checked
600
PriQOverflowException x RuntimeException
PriQOverflowException ()
PriQOverflowException (String)


606
Heap i PriQueueInterface
606
606
607
607
609
610
611
613
Heap (int)
isEmpty (): boolean
isFull (): boolean
enqueue (Comparable): void
reheapUp (Comparable): void
dequeue (): Comparable
reheapDown (Comparable): void
newHole (int, Comparable): int
Comparable [] elements
lastIndex int
maxIndex int

621
WeightedGraphInterface *

isEmpty (): boolean
ifFull (): boolean
addVertex (Object): void
hasVertex (Object): boolean
addEdge (Object, Object, int): void
weightIs (Object, Object): int
getToVertices (Object): UnboundedQueueInterface
clearMarks (): void
markVertex (Object): void
isMarked (Object): boolean
getUnmarked (): Object




625
isPath (WeightedGraphInterface,
Object, Object): boolean




627
isPath2 (WeightedGraphInterface,
Object, Object): boolean




632
shortestPaths (WeightedGraphInterface,
Object): void

prints results to System.out
637
WeightedGraph i WeightedGraphInterface
637
638
638
639
639
640
640
WeightedGraph ()
WeightedGraph (int)
addVertex (Object): void
indexIs (Object): int
addEdge (Object, Object, int): void
weightIs (Object, Object): int
getToVertices (Object): QueueInterface
int numVertices
int maxVertices
Object [] vertices
int [][] edges
boolean [] marks
Array implementation
Linked implementation left as an exercise:
9.35 and 9.36, pg 651.

Chapter 10

Pg
Class - *=interface
Pg
Methods Vars *=static
Notes
655
Sorts

initValues (): void
isSorted (): boolean
swap (int, int): void
printValues (): void
main
int [] values
test harness for sorting int arrays
should use toString method


661
minIndex (int, int): int
selectionSort (): void

Selection sort


666
bubbleUp (int, int): void
bubbleSort (): void

bubble sort


667
bubbleUp2 (int, int): boolean
shortBubble (): void

tests for already sorted


670
insertElement (int, int): void
insertionSort (): void

insertion sort


676
677
merge (int, int int, int): void
mergeSort (int, int): void

Merge sort


682
684
quickSort (int, int): void
split (int, int): int

Quick Sort


690
heapSort (): void
reheapDown (int, int, int)
reheapUp (int, int, int)

redefine reheaps to work on array heaps
code not included in text


695
bubbleUp (int, int): void
compare (Object, Object): int
equals (Object): boolean

use compareTo on arrays of Objects
696
SortCircle
696
new Comparator
minIndex (int, int, Comparator): int
selectionSort (Comparator): void
int xValue
int yValue
int radius
boolean solid
anonymous inner class
697
Sorts2
697
initValues (): void
swap (int, int): void
printValues (): void
minIndex (int, int, Comparator): int
selectionSort (Compartor): void
main
SortCircle [] values
main uses 2 instances of anonymous inner classes to implement the actual comparators.
706
Hashable *

hash (): int

create a hash of an object in a class


707
get (Hashable): Hashable
add (Hashable): void

find an element using a hash code
put an element into a hash table


709
get (Hashable): Hashable
add (Hashable): void

same functions, but also use linear probing