— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet144/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   140   141   142   143   144   145   146   147   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

146
 
chapter 6
import java.util.*;
public class 
DotComBust
{
private GameHelper helper = new GameHelper();
private ArrayList dotComsList = new ArrayList(); 
private int numOfGuesses = 0; 
private void 
setUpGame()
{
// fi rst make some dot coms and give them locations
DotCom one = new DotCom();
one.setName(“Pets.com”);
DotCom two = new DotCom();
two.setName(“eToys.com”);
DotCom three = new DotCom();
three.setName(“Go2.com”);
dotComsList.add(one);
dotComsList.add(two);
dotComsList.add(three);
System.out.println(“Your goal is to sink three dot coms.”);
System.out.println(“Pets.com, eToys.com, Go2.com”);
System.out.println(“Try to sink them all in the fewest number of guesses”);
for (DotCom dotComToSet : dotComsList) { 
ArrayList newLocation = helper.placeDotCom(3);
dotComToSet.setLocationCells(newLocation);

// close for loop

// close setUpGame method
private void 
startPlaying()
{
while(!dotComsList.isEmpty()) {
String userGuess = helper.getUserInput(“Enter a guess”); 
checkUserGuess(userGuess);

// close while
fi nishGame();

// close startPlaying method
 prep code test code
real code
real code

1
2
3
4
5
6
7
8
10
9
as long as the DotCom 
list is NOT empty
get user input
call our own checkUserGuess method
call our own finishGame method
print brief 
instructions for 
user
declare and initialize 
the variables we’ll need
repeat with each DotCom in the list
make three DotCom objects, give ‘em 
names, and stick ‘em in the ArrayList
ask the helper for a DotCom location
call the setter method on this DotCom 
to give it the location you just got 
from the helper
Sharpen your pencil
Annotate the code 
yourself!
Match the 
annotations at the 
bottom of each page 
with the numbers 
in the code. Write 
the number in the 
slot in front of the 
corresponding 
annotation. 
You’ll use each 
annotation just once, 
and you’ll need all of 
the annotations.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   140   141   142   143   144   145   146   147   ...   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