— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet122/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   118   119   120   121   122   123   124   125   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)


// close while

// close main
Just as you did with the SimpleDotCom class, be thinking about parts of this code 
you might want (or need) to improve. The numbered things are for stuff we 
want to point out. They’re explained on the opposite page. Oh, if you’re wonder-
ing why we skipped the test code phase for this class, we don’t need a test class for 
the game. It has only one method, so what would you do in your test code? Make 
separate class that would call main() on this class? We didn’t bother.
The game’s main() method
make a variable to track how 
many guesses the user makes
this is a special class we wrote that has 
the method for getting user input. for 
now, pretend it’s part of Java
DECLARE 
a vari-
able to hold user 
guess count, set it 
to 0
MAKE 
a SimpleDot-
Com object 
COMPUTE 

random number 
between 0 and 4
MAKE 
an int array 
with the 3 cell loca-
tions, and 
INVOKE 
setLoca-
tionCells on the dot 
com object 
DECLARE
a bool-
ean isAlive
WHILE
the dot 
com is still alive
GET
user input
// CHECK 
it
INVOKE 
checkYo-
urself() on dot com
INCREMENT 
numOfGuesses
IF 
result is “kill”
SET 
gameAlive to 
false
PRINT 
the number 
of user guesses
1
 prep code test code
real code
real code

2
1
make the dot com object
make a random number for the first 
cell, and use it to make the cell 
locations array
give the dot com its locations (the array)
make a boolean variable to track whether the game 
is still alive, to use in the while loop test. repeat 
while game is still alive.
get user input String
ask the dot com to check 
the guess; save the returned 
result in a String
increment guess count
was it a “kill”? if so, set isAlive to false (so we won’t 
re-enter the loop) and print user guess count

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   118   119   120   121   122   123   124   125   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish