— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet148/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   144   145   146   147   148   149   150   151   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

 prep code test code
real code
real code



150
 
chapter 6
import java.util.*;
public class 
DotCom
{
private ArrayList locationCells; 
private String name;
public void 
setLocationCells
(ArrayList loc) {
locationCells = loc;
}
public void 
setName
(String n) {
name = n;
}
public String 
checkYourself
(String userInput) { 
String result = “miss”;
int index = locationCells.indexOf(userInput);
if (index >= 0) {
locationCells.remove(index);
if (locationCells.isEmpty()) {
result = “kill”;
System.out.println(“Ouch! You sunk “ + name + “ : ( “);
} else {
result = “hit”;
} // close if
} // close if
return result;
} // close method
} // close class
DotCom’s instance variables:
- an ArrayList of cell locations
- the DotCom’s name
A setter method that updates 
the DotCom’s location.
(Random location provided by 
the GameHelper placeDotCom( ) 
method.)
Your basic setter method
The ArrayList indexOf( ) method in 
action! If the user guess is one of the 
entries in the ArrayList, indexOf( ) 
will return its ArrayList location. If 
not, indexOf( ) will return -1.
Tell the user when a DotCom has been sunk.
Using the isEmpty( ) method to see if all 
of the locations have been guessed
Using ArrayList’s remove( ) method to delete an entry.
The final version of the 
DotCom class
Return: ‘miss’ or ‘hit’ or ‘kill’.
 prep code test code
real code
real code

the 
DotCom 
code



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   144   145   146   147   148   149   150   151   ...   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