— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet139/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   135   136   137   138   139   140   141   142   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

get to know the 
Java API 
you are here
4
139
import java.util.ArrayList;
public class DotCom {
private 
ArrayList
locationCells;
// private int numOfHits; 
// don’t need that now
public void setLocationCells(
ArrayList
loc) {
locationCells = loc;
}
public String checkYourself(String userInput) {
String result = “miss”;
int index = locationCells.indexOf(userInput);
if (index >= 0) {
locationCells.remove(index);
if (locationCells.isEmpty())
{
result = “kill”;
} else {
result = “hit”;

// close if

// close outer if
return result;

// close method

// close class
New and improved DotCom class
 prep code test code
real code
real code

Change the String array to an ArrayList that holds Strings.


Ignore this line for 
now; we talk about 
it at the end of the 
chapter .
Find out if the user guess is in the 
ArrayList, by asking for its index. 
If it’s not in the list, then indexOf() 
returns a -1. 
If index is greater than or equal to 
zero, the user guess is definitely in the 
list, so remove it.
If the list is empty, this 
was the killing blow!
New and improved argument name.


140
 
chapter 6
making the 
DotComBust
Let’s build the REAL game:
“Sink a Dot Com”
We’ve been working on the ‘simple’ version, but now 
let’s build the real one. Instead of a single row, we’ll 
use a grid. And instead of one DotCom, we’ll use 
three.
Goal: Sink all of the computer’s Dot Coms in the 
fewest number of guesses. You’re given a rating level 
based on how well you perform.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   135   136   137   138   139   140   141   142   ...   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