Get (Ebook PDF) Introduction To JAVA Programming and Data Structures Comprehensive Version 11 Free All Chapters
Get (Ebook PDF) Introduction To JAVA Programming and Data Structures Comprehensive Version 11 Free All Chapters
com
https://ebooksecure.com/product/ebook-pdf-
introduction-to-java-programming-and-data-
structures-comprehensive-version-11/
https://ebooksecure.com/product/ebook-pdf-introduction-to-java-
programming-and-data-structures-comprehensive-version-11th-global-
edition/
ebooksecure.com
https://ebooksecure.com/download/introduction-to-java-programming-
comprehensive-version-ebook-pdf/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-java-foundations-
introduction-to-program-design-and-data-structures-5th-edition/
ebooksecure.com
https://ebooksecure.com/product/original-pdf-differential-equations-
with-boundary-value-problems-9th/
ebooksecure.com
World Regions in Global Context: Peoples, Places, and
Environments 6th Edition by Sallie A. Marston (eBook PDF)
https://ebooksecure.com/product/world-regions-in-global-context-
peoples-places-and-environments-6th-edition-by-sallie-a-marston-ebook-
pdf/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-financial-management-theory-
practice-16th-edition/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-essentials-of-human-anatomy-
physiology-12th-edition/
ebooksecure.com
https://ebooksecure.com/download/radar-remote-sensing-applications-
and-challenges-ebook-pdf/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-fundamentals-of-machine-
component-design-6th-edition/
ebooksecure.com
(eBook PDF) Chemical Principles 7th Edition by Peter
Atkins
https://ebooksecure.com/product/ebook-pdf-chemical-principles-7th-
edition-by-peter-atkins/
ebooksecure.com
Introduction to JAVA™
Introduction to Java™ Programming and Data Structures
Comprehensive Version
Eleventh Edition
Y. Daniel Liang
1–17
ISBN-10: 0-13-467094-9
ISBN-13: 978-0-13-467094-2
Preface
Dear Reader,
Many of you have provided feedback on earlier editions of this book, and
your comments and suggestions have greatly improved the book. This edition
has been substantially enhanced in presentation, organization, examples,
exercises, and supplements.
fundamentals-first
problem-driven
data structures
comprehensive version
brief version
AP Computer Science
The best way to teach programming is by example, and the only way to learn
programming is by doing. Basic concepts are explained by example and a
large number of exercises with various levels of difficulty are provided for
students to practice. For our programming courses, we assign programming
exercises after each lecture.
Our goal is to produce a text that teaches problem solving and programming
in a broad context using a wide variety of interesting examples. If you have
any comments on and suggestions for improving the book, please email me.
Sincerely,
Y. Daniel Liang
www.cs.armstrong.edu/liang
www.pearsonhighered.com/liang
The default and static methods are introduced for interfaces in Chapter
13.
The GUI chapters are updated to JavaFX 8. The examples are revised.
The user interfaces in the examples and exercises are now resizable and
displayed in the center of the window.
More examples and exercises in the data structures chapters use lambda
expressions to simplify coding. Method references are introduced along
with the Comparator interface in Section 20.6.
Use the default methods for interfaces in Java 8 to redesign and simplify
MyList, MyArrayList , MyLinkedList, Tree, BST, AVLTree, MyMap,
MyHashMap, MySet, MyHashSet, Graph, UnweightedGraph, and
WeightedGraph in Chapters 24–29.
FXML and the Scene Builder visual tool are introduced in Chapter 31.
The Companion Website has been redesigned with new interactive quiz,
CheckPoint questions, animations, and live coding.
Pedagogical Features
The book uses the following elements to help students get the most from the
material:
Notes, Tips, Cautions, and Design Guides are inserted throughout the
text to offer valuable advice and insight on important aspects of program
development.
Note
Provides additional information on the subject and reinforces important
concepts.
Tip
Teaches good programming style and practice.
Caution
Helps students steer away from the pitfalls of programming errors.
Design Guide
Provides guidelines for designing programs.
Flexible Chapter Orderings
The book is designed to provide flexible chapter orderings to enable GUI,
exception handling, recursion, generics, and the Java Collections Framework
to be covered earlier or later. The diagram on the next page shows the chapter
dependencies.
Organization of the Book
The chapters can be grouped into five parts that, taken together, form a
Exploring the Variety of Random
Documents with Different Content
“Guess I shouldn’t have been so funny, whacking you that way,” Roy
muttered, and smiled weakly. “I don’t want that thing on my head, Teddy. If
Nell sees me coming all tied up she’ll think something happened.”
“And nothing did happen—we’ve just been to a tea, and you got a little
damp trying to do a six beat crawl in the punch bowl,” Teddy said
sarcastically. “Listen to me, bucko! They’ll know you took a spill. How can
they help knowing? But what of it? Tell ’em you got out all right—crawled
ashore. Remember that? You crawled ashore.”
He glanced at Roy significantly.
If any one else had saved his life and Roy were asked to say nothing of
it, he would have refused immediately. The smallest recompense one may
offer to his rescuer is to acknowledge the debt publicly. But between these
two there was no such formality. They were not concerned with what others
thought of their relationship to one another. Calmly each accepted the full
devotion of his brother, knowing that his own was accepted in turn. Thus,
when Teddy signified that he did not wish known the part he had played in
saving Roy, the other agreed at once to keep the true story hidden.
“All right, I crawled ashore,” Roy said. “And if you feel like playing
doctor, go right ahead.”
He edged the pony toward Teddy and submitted to the ministrations of
his brother. When the large handkerchief had been tied about the cut, Teddy
removed his hat and placed it lightly on his brother’s head. Roy’s own hat
was floating somewhere in Rocky Run River.
“It won’t hurt you with that bandage on,” he declared. “And this sun is
pretty strong. No, leave it tilted that way.”
“Yes, doctor,” Roy replied meekly. “Anything you say. Now they’ll think
I’m a gunman.”
“You look like a pirate,” Teddy laughed. “How does that bronc ride,
Roy?”
“Pretty steady. Shakes now and then, that’s all. Jiminy! I didn’t notice
that long scratch on Star’s hind leg.” He glanced down at the pony Teddy
was leading. “Let me take him for a while.”
“No, you’ve got enough to attend to,” Teddy insisted. “Star’s all right.
Needs a good rubdown, that’s all, and he’ll soon get it. We’ll be at the ranch
in fifteen minutes.”
“Meantime—” Roy pulled his pony to a halt and began searching
through his pockets.
“Money?” Teddy asked. “Forget it. If you had any in your pockets, it’s
gone. Besides, what can you buy for eleven cents?”
“Not money,” Roy replied. “It’s—ah, here we have it!” He pulled a
sodden mass from one of his pockets. The gleam of tinfoil showed as he
held the object proudly up.
“For the love of Pete, what’s that?” Teddy gasped. “A first-aid kit?”
“Chocolate!” Roy exclaimed. “Real, honest-to-goodness chocolate—
even if it is a little mildewed. Here, take a piece.”
“Not me,” Teddy said firmly. “I like my chocolate in a cup or dry—but
not half and half. You go ahead and eat it.”
“I will,” Roy answered, munching on the candy. “It’s good, too.”
“Is it?” Teddy commented. “Well, that’s nice.”
He could think of nothing else to say, and the two boys rode for a while
in silence. The chocolate gave Roy added strength, and gradually his cheeks
were resuming their normal color, that peculiar reddish brown that comes to
the faces of men who live in the open. There is nothing more sickly looking
than to see a man whose skin is tanned go suddenly pale beneath it.
“You know,” Roy said after a few minutes, “I would have been after this
bronco as quickly as you, only my stirrup slipped.”
“I thought something happened. I—er—thought I had him when he
doubled back and got away again. Hope Nell didn’t get hurt when she fell
off.”
“She didn’t,” Roy assured him. “Wanted to know if I thought she was a
bag of potatoes when I suggested that Belle and Ethel carry her in. Or
maybe I did say cart her in.”
“You probably did. From a youth you were given to the use of the
correct expression in the incorrect place.”
Another period of silence. Then, from Teddy:
“Well, I’m glad of that.”
“Huh?”
“That she didn’t get hurt when she fell off. Just continuing the
conversation. How’s your head feel now?”
“Is by me Ho Kay! Such is the resilience of youth that—”
“Applesauce! Snakes, it’s getting hotter by the minute! I’m nearly dry.
And that reminds me—”
“Yes, I thought of that, too,” Roy said meaningly. “How’d you get wet
watching me swim to shore?”
“Well, I waded in and helped you, then. That’ll pass.”
Both Roy and Teddy knew the real reason for not saying anything about
the rescue. In the first place, Nell Willis would berate herself for having
fallen off, and so, consequently, having exposed Roy to danger. In the
second place—and this Teddy realized more than Roy—there would be
small glory to Roy in having to be dragged from the river. And after all, it
was Teddy’s fault, for his cry startled the runaway. For these and other
reasons the boys judged it best that none but themselves should know the
true story.
Ahead of them now was the hill that over-topped the 8 X 8 ranch. Within
ten minutes they would be greeting the girls.
Suddenly Teddy, who was ahead leading Star, held up his hand.
“Got a question to ask?” Roy said laconically. “Well, go ahead. But
remember teacher isn’t here to—”
“I heard a yell,” Teddy interrupted shortly. “A funny yell.”
“A funny yell?” Roy noticed the seriousness of his brother’s face and did
not carry the joking further. “What do you mean?”
“Well, it sounded like a yell for help. Pipe down a second while I listen.”
The horses were brought to a halt. The boys remained silent, but heard
nothing but the murmur of the river in the distance.
“Reckon I was mistaken,” Teddy said finally. “I must be hearing things.
What say we get a wiggle on? You feel all right?”
“Sure! Step on it. Don’t worry about me. That chocolate brought me
around.”
They swung their mounts into a trot. Both Star and Flash were well
schooled, and could trot as well as any Eastern pony. Nearly all Western
steeds will go right from a walk into a gallop, since there are few times
when a trot is demanded of them. The Western stirrup is usually too long to
allow “posting,” which is the peculiar rising and falling of the rider to co-
ordinate with the pony’s motion.
At the foot of the hill was a small clump of trees, the only shade visible
for miles around. Teddy headed for this.
“Any special reason?” Roy inquired.
“For going this way? Well, it’s no longer, and that yell—if it was a yell
—came from this direction. We might take a look—see?”
“Check! We shall investigate the ghostly sound.”
The boys were intent on this new experience now. The fall into the river
was forgotten for the moment. Roy scarcely realized that his head was
injured, yet was forcibly reminded of the fact when he took off his hat to
rub an itchy place.
“Man’s yell?” Roy asked after an interval. They were approaching the
trees.
“I thought so. Not shrill enough for a woman or a girl. And it couldn’t
have been a cat.” Teddy was referring to a mountain lion, not a house cat.
Coming into the shadow of the trees, Teddy halted again, as a man does
who is uncertain of things around him. The woods were about a quarter of a
mile deep, tapering off at one end like a triangle.
“Going to ride through?” Roy asked.
“Might as well.” He urged Flash forward. “Maybe—”
The sentence was never finished. So close to them that they started
violently, as did their horses, came a cry:
“Don’t! For heaven’s sake, don’t shoot! I haven’t got it with me, I tell
you! I—”
The roar of a gun cut the voice short. It died out in a groan. From the
point of the triangle two men rushed into the open—two men, riding hard
and leading a third horse.
CHAPTER IV
Stolen Nuggets
Teddy Manley, lines of anxiety in his face, went into the parlor. The
doctor saw him and motioned him to one side.
“Listen, Teddy,” he said quickly; “the way things look now, he’s got a
chance—a slim one, but a chance. Whoever put that bandage around his
neck probably saved his life. But he’s worrying about something—wouldn’t
tell me what it was. We can’t have that. He needs everything in his favor if
he’s to pull through. Understand?”
Teddy looked at the physician.
“It’s this way, doc,” he answered in a low voice. “He’s been robbed.
Now, suppose he asks me where his money—or whatever he had with him
—is? What’ll I say?”
Doctor Ring thought for a moment. The man’s face was turned to the
wall.
“Tell him the truth,” the doctor said suddenly. “We can’t lie, although if
it meant saving a patient’s life I’d lie like Ananias. But he’ll ask to see the
money if we tell it’s been saved. We can’t take a chance on that. Tell him
the truth.”
“Right.”
Teddy went slowly toward the cot. As the man heard him coming, he
turned his whole body and stared at the boy. The neck was swathed in
heavy gauze, making it impossible for him to move his head.
“Well, sir,” Teddy called cheerfully, “how are things?”
The bloodless lips moved and a disappointed look came into the eyes.
“That’s not the one,” the man whispered. “He looks like him, but he
ain’t. I want—” His breath caught, and he stopped, his bony hands
clenching.
“Where’s Roy?” Belle asked quickly. She was standing beside Teddy.
“Can’t somebody get him?”
But there was no need for that. The screen door whined and Roy entered.
As the man on the cot saw him, his face lighted up.
“Come here,” he whispered weakly. “I want to—ask—”
Roy glanced toward the doctor for directions, and received a nod. He
went to the side of the man.
“I’m glad to see you’re better,” he said simply. “What was it that you
wanted to ask me?”
The man’s hand tapped the coverlet impatiently.
“That’s right,” he breathed. “You’re the—one. Listen, boy—listen—” He
raised up on one elbow, and the doctor crossed swiftly to him.
“None of that,” he said sternly. “You promised to keep quiet if I let you
see him. Lie back, now.”
“Right—you’re the doctor.” A mirthless grin twisted the thin lips. “I’ll
be good. Listen, boy!” He took a deep breath. “Where’s my nugget?”
“Nugget!” Roy started back. “Is that what you—what nugget?” he asked
blankly.
“My nugget! My nugget! The one I worked for, slaved for, fought for!
Where is it?” The eyes were burning.
“I’m afraid—” Roy hesitated. “Say, what’s your name?”
“Decker. Jerry Decker. I’m a miner. I had a nugget with me that was
worth—” He stopped. “Some smaller ones, too,” he continued in a toneless
voice. The excitement seemed to drain his strength. “My nuggets—where
are they?” he finished faintly.
Roy glanced down at him pityingly.
“Mr. Decker, your nuggets are gone,” he said slowly. “You’ve been
robbed.”
“Robbed!” The word was wrung from him. “Robbed! The nuggets I
worked for—slaved for! Worth—”
His eyes opened wide, his whole body tensed. Then, with a sigh, he
relaxed. The eyes closed. The corners of the mouth went down.
“Watch it,” came a voice behind Roy. It was the doctor. “Get his arm out
from under that blanket—quick!”
Roy, understanding, did as he was told. There was a swift jab of a
hypodermic needle. In a moment the breathing resumed, the pulse fluttered.
Doctor Ring watched the face anxiously.
“I was afraid of that,” he said softly. “It was too much for him.” There
was a moment’s silence. Then the lips moved again, and a faint flush of
color came to the cheeks.
The doctor gave a “whew!” of relief.
“He’ll come out of it now,” he said finally. “It’s better to have it over
with. Besides, he may have needed just that stimulus to help him fight. Now
he’ll get well just to recover his nuggets.” His tone was hopeful. Plainly he
had been in doubt as to whether or not he had done the right thing in letting
Roy see and talk to the patient.
Roy walked to the other side of the room after giving one more glance at
the unconscious man. At that moment Mr. Ball descended the stairs.
“How’s he comin’?” he whispered. “Any better?”
The doctor nodded.
“I think so,” he replied. “I’ll have to stay here for a while yet.”
“All right,” Peter Ball remarked. “I sure hope he makes out. What
happened to him? Miner, ain’t he?”
Mr. Ball, Teddy, and Roy went into the yard. Bug Eye was waiting for
them.
“He’s a miner, and he’s been robbed,” Roy declared. “Name’s Jerry
Decker.”
“Robbed! Jumpin’ catamounts! What’s he been robbed of?”
“Nuggets, he says,” Teddy replied. “He was just going to tell us how
much they were worth when he went off again. Wonder where he was
mining.”
“The most likely place would be Nugget Camp,” Mr. Ball said. “They
been placerin’ around there for the last ten years, but I never heard tell of
anybody gettin’ rich from it.”
“Nugget Camp!” Bug Eye burst out. “I know where that is, boss! Say, I
heard tell around town of a strike bein’ made there. But nobody seemed to
know who made it. Nugget Camp, hey? So that’s where he come from!”
“Well, I’m only guessin’,” Mr. Ball admitted. “But that’s the only minin’
place anywheres near here.”
“That’s where he came from, all right,” Teddy asserted. “He must have
been on his way to town when he got shot up and robbed.” He stopped, and
looked over at Mr. Ball. “Do you think there’s a chance—” he began.
“We’ll try it,” the rancher interrupted quickly, sensing what Teddy
meant. “They’re probably out of this vicinity now, but we owe it to that
poor old geezer to have a look, anyhow. Bug Eye, get my bronc. You’re
comin’, too.”
“Sure, boss!” the puncher answered eagerly. “Right away?”
“Right away. I’ll tell my wife.” He walked swiftly toward the house.
“Looks like business,” Teddy declared. “How’d you find Star?”
“O. K. Jules Kolto fixed him up for me. He’ll be all right to ride. Take
some of the stiffness out of him. Come on, let’s get going.”
“Hey!” Mr. Ball called from the porch. Then, as he recalled the sick man
within, he motioned with his arm. When Teddy and Roy approached, he
said: “We’ll get some chuck first. Might be a long ride.”
He, Teddy, Roy, and Bug Eye ate together. In the middle of the meal Mr.
Ball saw the cut on Roy’s head, as the boy unwittingly brushed back his
hair. The rancher heard the story of the spill into the river and insisted that
Roy should see the doctor before the party started.
So with a strip of adhesive tape covering the wound, Roy mounted Star
and waited for Mr. Ball to give the signal to start. The doctor had declared
that Roy’s cut was superficial, and there would be no danger in riding.
“All set, boys?” Mr. Ball called. He had provided Teddy and Roy with
dry clothes—although their own were nearly dry by that time—and with
guns.
“All set, boss,” Bug Eye answered. “Let’s go!”
The three girls, Nell, Ethel, and Belle Ada, waved to them from the
porch.
“Good luck!” Belle called softly.
With a swirl of their hats the boys leaped their broncos forward. The
hunt was on.
They made for the clump of woods where Decker had been found.
“That’ll be a starting point, anyhow,” Mr. Ball asserted. “We may strike
something there that’ll help us. Otherwise, it’ll be like lookin’ for a needle
in a haystack.”
“Sure will,” Teddy agreed. “Baby, I’d like to come across those
waddies!”
“I’ll tell a maverick!” Roy ejaculated. “Knocking off an old man after
robbing him, then taking his bronc!”
There was little more said until they reached the woods. Roy showed just
where they had picked Decker up, and even the marks where his body had
lain, his head supported by Roy’s leg.
“We saw ’em come riding out of there,” Teddy declared, pointing to the
edge of the trees. “See—where it makes sort of a triangle?”
“Uh-huh,” Mr. Ball responded. “Which direction did they take?”
“Swung to the right. Teddy yelled at me then, and I turned back. Oh,
they’re well on their way by now.”
“Afraid so.” Mr. Ball had dismounted, and was examining the ground
intently. “Suppose you fellers get off an’ take a look around. May spot
something.”
“Clues, hey, boss?” Bug Eye cried excitedly. “Snakes!”
“Yea, clues. Make believe you’re a detective.” The rancher stood directly
on the place where Roy had told him Decker was lying. Then he faced
about.
“This way they went,” he said, more to himself than to the others. “You
can see the hoofprints of their broncos. One, two, three ponies.”
“They took his so he couldn’t follow, I reckon,” Teddy said.
Mr. Ball did not reply. He walked slowly forward.
Presently he uttered an exclamation and stopped. Then he bent to the
ground.
“What is it, boss—find somethin’?” Bug Eye asked eagerly.
Mr. Ball nodded.
“Take a look,” he said in a queer voice. “Never saw one of these out here
before.”
The others grouped about him. He held something up to them.
“Know what it is?” he said quietly.
Bug Eye shook his head. Teddy and Roy answered nothing.
“It’s a German pistol—a Mauser,” the rancher said deliberately. “One
shell has been fired.”