You are on page 1of 5


!"#$%&%& () *++,-./0.1 2

CCMÞ1010 DL - Summer 2014

Ass|gnment S
More Worker Class pracLlce -
mulLlple worker classes
More lf/else and loop pracLlce
wlLh arrays

Array MeLhods
- Arrays as lnsLance varlables
- Search for an elemenL ln an
array (llnear search)

Çuest|on 1:

lor AsslgnmenL 3, we're golng Lo lmplemenL a word puzzle game. 1he
program, ASÇ1.[ava, wlll load a dlcLlonary flle lnLo memory. lL wlll
lnsLanLlaLe a new puzzle ob[ecL by passlng lL a random word selecLed from
Lhe dlcLlonary. 1he program wlll lnLeracL wlLh Lhe user by flrsL asklng Lhem
how many guesses Lhey wanL Lo allow for Lhe puzzle lnLeracLlon before lL
ends. nexL lL wlll ask Lhe users for guesses unLll Lhe game ends. 1he game
wlll end when Lhe user guesses Lhe word, or Lhey have guessed Lhe max
number of guesses. Lach guess may be a slngle leLLer, or a guess of Lhe
word. AfLer each puzzle ls played Lhe program wlll ask Lhe user lf Lhey
would llke Lo play agaln. 1he program wlll qulL when Lhe play agaln
quesLlon ls answered wlLh any sLrlng conLalnlng Lhe leLLer ºn".

1he A3C1.[ava program flle wlll conLaln Lwo worker classes, Lhe dlcLlonary
class and Lhe puzzle class. 1he ulcLlonary class ls provlded for you and wlll
manage accesslng a new random word for each puzzle. ?ou wlll wrlLe Lhe
Þuzzle class. 1hls class wlll manage keeplng Lrack of whlch leLLers of Lhe
alphabeL have been guessed so far. lL wlll keep Lrack of whlch leLLers ln
puzzle word should be shown durlng Lhe currenL sLaLe of Lhe puzzle. lL wlll
also keep Lrack of Lhe number of guesses made so far. lL wlll expose Lhe
currenL sLaLe of Lhe puzzle vla Lhe class' LoSLrlng meLhod. 8equlred
componenLs of Lhe puzzle are ouLllned ln Lhe Lable below. ?ou may
lmplemenL addlLlonal prlvaLe meLhods ln order Lo break up Lasks lnLo
smaller componenLs.

!"#$%&%& () *++,-./0.1 2

8egln wlLh Lhe A3C1.[ava flle provlded on Lhe course webslLe. 1he
meLhods requlred for loadlng Lhe dlcLlonary flle has been provlded for you
as well as selecLlng a random word. CreaLe meLhod(s) ln A3C1.[ava Lo
supporL approprlaLe user lnLeracLlon for Lhe game as descrlbed above. use
Lhe classes Scanner, ulcLlonary, and Þuzzle

[[avadoc commenLs have noL been provlded for Lhls asslgnmenL.
8emember Lo add Lhese for all your meLhods.

lnclude Lhe followlng lnsLance varlables ln Lhe Þuzzle Class:
Var|ab|e type Descr|pt|on
SLrlng 1he word LhaL ls belng guessed. 1hls ls
never exposed Lo Lhe user.
char array An array of characLers, shows '_' for any
lndex noL guessed yeL and Lhe leLLer from
Lhe word for any lndex where Lhe leLLer
ln quesLlon has been guessed.
char array An array of characLers represenLlng Lhe
26 leLLers of Lhe alphabeL. Shows '_' lf a
leLLer has noL been guessed yeL and a
leLLer lf lL has been guessed.
lnL An lnLeger sLorlng Lhe maxlmum number
of guesses allowed for Lhe puzzle.
lnL An lnLeger sLorlng Lhe number of guesses
made so far durlng Lhls puzzle.

SLaLlc consLanLs

Var|ab|e type Descr|pt|on
lnL A defaulL value for defaulL max guesses.
char A char value Lo for 'a' or 'z' converL a
char value lnLo an lnLeger lndex for
accesslng lLems ln Lhe alphabeL array.
char A char value represenL blanks '_'

!"#$%&%& () *++,-./0.1 2

lnclude Lhe followlng componenLs and meLhods ln Lhe Þuzzle Class
Item Descr|pt|on
consLrucLor AccepLs a sLrlng value as an argumenL.
lnsLanLlaLes Lhe Lwo arrays wlLh blanks,
lnsLanLlaLes Lhe maxlmum guesses
varlables Lo Lhe defaulL value, and
lnsLanLlaLes Lhe guesses value Lo 0
modlfler MeLhod Lo seL Lhe varlable for maxlmum
applyCuess(SLrlng guess) Þubllc meLhod LhaL accepLs a sLrlng as an
argumenL and reLurns a sLrlng lndlcaLlng
lf Lhe guess was successful or noL, as well
as Lhe currenL sLaLus of Lhe puzzle. lf Lhe
guess ls 1 characLer long Lhen Lhe
meLhod should check Lo see lf LhaL leLLer
occurs ln Lhe puzzle word. lf Lhe guess ls
any oLher slze Lhen Lhe meLhod check for
an exacL whole word maLch.
(8ecommend breaklng Lhls meLhod up
by addlng ÞrlvaLe lnsLance meLhods Lo
compleLe secLlons of Lhe Lasks.)
gameCver() Þubllc meLhod LhaL accepLs no
argumenLs. 8eLurns Lrue lf elLher Lhe
number of guesses made have exceeded
Lhe number of guesses allowed, or all Lhe
leLLers ln Lhe word have been fllled ln. ln
any oLher case Lhe meLhod reLurns false.
LoSLrlng() 8eLurns a sLrlng reporLlng Lhe currenL
sLaLus of Lhe puzzle lncludlng Lhe leLLers
guessed ln Lhe puzzle word, Lhe leLLers of
Lhe alphabeL LhaL have been guessed,
how many guesses have been made,
how many guesses can be made, and
how many guesses are lefL. lf Lhere are
no guesses lefL, lL should lnclude whaL
Lhe word was.

!"#$%&%& () *++,-./0.1 2

8ecommended SupporLlng SLaLlc meLhods

geLulsplay AccepLs a char array as an argumenL and
reLurns a sLrlng. Complles Lhe characLers
ln Lhe array lnLo a sLrlng placlng a space
beLween each char. So lf you had a char
array llke ['[','u','_','p'} Lhe resulLlng
sLrlng would be º[ u m_ p". use Lhls Lo
show Lhe leLLers of Lhe alphabeL LhaL
have been guessed, and Lhe leLLers of Lhe
word LhaL have been guessed.
flllLlsL AccepLs an lnL as an argumenL and
reLurns a char array of LhaL slze fllled
wlLh '_' values. use Lhls Lo flll Lhe array
for Lhe leLLers of Lhe alphabeL, and for
Lhe array keeplng Lrack of leLLers of Lhe
word LhaL have been guessed.

CuLpuL Lxamples:

!"#$%&%& () *++,-./0.1 2

And aL Lhe end of Lhe game.


An elecLronlc copy of your source flles, ln a zlpped folder, musL also be
submlLLed ln uslng Lhe hand ln faclllLy on Lhe course web slLe. 1he
elecLronlc copy musL be submlLLed by 11:39pm on Lhe due daLe.