— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

112
 
chapter 5
One last class: GameHelper
 prep code test code
real code
real code

We made the dot com class.
We made the game class.
All that’s left is the helper class— the one with the 
getUserInput() method. The code to get command-
line input is more than we want to explain right now. 
It opens up way too many topics best left for later. 
(Later, as in chapter 14.)
import java.io.*;
public class GameHelper {
public String getUserInput(String prompt) {
String inputLine = null;
System.out.print(prompt + “ “);
try {
BufferedReader is = new BufferedReader(
 
 new InputStreamReader(System.in));
inputLine = is.readLine();
if (inputLine.length() == 0 ) return null; 
} catch (IOException e) {
System.out.println(“IOException: “ + e);
}
return inputLine;
}
}
I pre-cooked 
some code so you 
don’t have to make 
it yourself. 
Ready-bake 
Code
Just copy* the code below and compile it into 
a class named GameHelper. Drop all three 
classes (SimpleDotCom, SimpleDotComGame, 
GameHelper) into the same directory, and make it 
your working directory.
Whenever you see the
logo, you’re see-
ing code that you have to type as-is and take on faith. 
Trust it. You’ll learn how that code works later.
Ready-bake 
Code
*We know how much you enjoy typing, but for those rare 
moments when you’d rather do something else, we’ve made 
the Ready-bake Code available on wickedlysmart.com.
GameHelper 
class (Ready-bake)



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   120   121   122   123   124   125   126   127   ...   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