— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

testcode
 

real (Java) code
ß
Prepcode should describe what to do, not how 
to do it. Implementation comes later.
ß
Use the prepcode to help design the test 
code.
ß
Write test code before you implement the 
methods.
Howdy from Ghost Town
ß
Choose for loops over while loops when you 
know how many times you want to repeat the 
loop code.
ß
Use the pre/post increment operator to add 1 
to a variable (x++;)
ß
Use the pre/post decrement to subtract 1 from 
a variable (x--;)
ß
Use
Integer.parseInt()
to get the int 
value of a String.
ß
Integer.parseInt()
works only if the 
String represents a digit (“0”,”1”,”2”, etc.)
ß
Use break to leave a loop early (i.e. even if 
the boolean test condition is still true).


110
 
chapter 5
public static void main(String[] args) {
int numOfGuesses = 0;
GameHelper helper = new GameHelper();
SimpleDotCom theDotCom = new SimpleDotCom();
int randomNum = (int) (Math.random() * 5); 

int[] locations = {randomNum, randomNum+1, randomNum+2}; 
theDotCom.setLocationCells(locations);
boolean isAlive = true;
while(isAlive == true) {
String guess = helper.getUserInput(“enter a number”);
String result = theDotCom.checkYourself(guess);
numOfGuesses++;
if (result.equals(“kill”)) {
isAlive = false;
System.out.println(“You took “ + numOfGuesses + “ guesses”);

// close if

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   117   118   119   120   121   122   123   124   ...   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