— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet514/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   510   511   512   513   514   515   516   517   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

yes,
no
Fill-in-the-blanks
Sharpen your pencil


556
 
chapter 16
Uh-oh. The sorting all works, but now we have duplicates...
The sorting works great, now we know how to sort on both title (using the Song object’s 
compareTo() method) and artist (using the Comparator’s compare() method). But there’s 
a new problem we didn’t notice with a test sample of the jukebox text fi le—the sorted list 
contains duplicates. 
It appears that the diner jukebox just keeps writing to the fi le regardless of whether the 
same song has already been played (and thus written) to the text fi le. The SongListMore.txt 
jukebox text fi le is a complete record of every song that was played, and might contain the 
same song multiple times.
File Edit Window Help TooManyNotes
%java Jukebox4
[Pink Moon: Nick Drake, Somersault: Zero 7, Shiva Moon: Prem 
Joshua, Circles: BT, Deep Channel: Afro Celts, Passenger: 
Headmix, Listen: Tahiti 80, Listen: Tahiti 80, Listen: Tahiti 
80, Circles: BT]
[Circles: BT, Circles: BT, Deep Channel: Afro Celts, Listen: 
Tahiti 80, Listen: Tahiti 80, Listen: Tahiti 80, Passenger: 
Headmix, Pink Moon: Nick Drake, Shiva Moon: Prem Joshua, 
Somersault: Zero 7]
[Deep Channel: Afro Celts, Circles: BT, Circles: BT, Passenger: 
Headmix, Pink Moon: Nick Drake, Shiva Moon: Prem Joshua, Listen: 
Tahiti 80, Listen: Tahiti 80, Listen: Tahiti 80, Somersault: 
Zero 7]
Before sorting.
SongListMore.txt
Pink Moon/Nick Drake/5/80
Somersault/Zero 7/4/84
Shiva Moon/Prem Joshua/6/120
Circles/BT/5/110
Deep Channel/Afro Celts/4/120
Passenger/Headmix/4/100
Listen/Tahiti 80/5/90
Listen/Tahiti 80/5/90
Listen/Tahiti 80/5/90
Circles/BT/5/110
The SongListMore text file now has duplicates in 
it, because the jukebox machine is writing every song 
played, in order. Somebody decided to play “Listen” 
three times in a row, followed by “Circles”, a song 
that had been played earlier.
We can’t change the way the text file is written 
because sometimes we’re going to need all that 
information. We have to change the java code.
After sorting using 
the Song’s own 
compareTo() method 
(sort by title).
After sorting using 
the ArtistCompare 
Comparator (sort by 
artist name).

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   510   511   512   513   514   515   516   517   ...   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