Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

4.5 9 distance in kilometers codehs

18/10/2021 Client: muhammad11 Deadline: 2 Day

Java Assignment2

Digital Resources for Students

Your new textbook provides 12-month access to digital resources that may include VideoNotes (step-by-step video tutorials on programming concepts), source code, web chapters, quizzes, and more. Refer to the preface in the textbook for a detailed list of resources.

Follow the instructions below to register for the Companion Website for Daniel Liang’s Introduction to Java™ Programming and Data Structures, Comprehensive Version, Eleventh Edition, Global Edition.

1. Go to www.pearsonglobaleditions.com/liang 2. Enter the title of your textbook or browse by author name. 3. Click Companion Website. 4. Click Register and follow the on-screen instructions to create a login name and password.

Use a coin to scratch off the coating and reveal your access code. Do not use a sharp knife or other sharp object as it may damage the code.

Use the login name and password you created during registration to start using the digital resources that accompany your textbook.

IMPORTANT: This prepaid subscription does not include access to MyProgrammingLab, which is available at www.myprogramminglab.com for purchase.

This access code can only be used once. This subscription is valid for 12 months upon activation and is not transferable. If the access code has already been revealed it may no longer be valid.

For technical support go to https://support.pearson.com/getsupport

Liang_11_1292221879_ifc_Final.indd 1 17/11/17 9:19 PM

Digital Resources for Students

Your new textbook provides 12-month access to digital resources that may include VideoNotes (step-by-step video tutorials on programming concepts), source code, web chapters, quizzes, and more. Refer to the preface in the textbook for a detailed list of resources.

Follow the instructions below to register for the Companion Website for Daniel Liang’s Introduction to Java™ Programming and Data Structures, Comprehensive Version, Eleventh Edition, Global Edition.

1. Go to www.pearsonglobaleditions.com/liang 2. Enter the title of your textbook or browse by author name. 3. Click Companion Website. 4. Click Register and follow the on-screen instructions to create a login name and password.

Use a coin to scratch off the coating and reveal your access code. Do not use a sharp knife or other sharp object as it may damage the code.

Use the login name and password you created during registration to start using the digital resources that accompany your textbook.

IMPORTANT: This prepaid subscription does not include access to MyProgrammingLab, which is available at www.myprogramminglab.com for purchase.

This access code can only be used once. This subscription is valid for 12 months upon activation and is not transferable. If the access code has already been revealed it may no longer be valid.

For technical support go to https://support.pearson.com/getsupport

Liang_11_1292221879_ifc_Final.indd 1 17/11/17 9:19 PM Digital_Resources_for_Students.indd 1 1/17/18 8:14 PM

IntroductIon to

Java ProgrammIng and

data StructureS comPrehenSIve verSIon

Eleventh Edition

Global Edition

Y. daniel Liang Armstrong State University

330 Hudson Street, NY NY 10013

A01_LIAN1878_11_GE_FM.indd 1 1/2/18 11:57 PM

To Samantha, Michael, and Michelle

Java™ and Netbeans™ screenshots ©2017 by Oracle Corporation, all rights reserved. Reprinted with permission. Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on the appropriate page within text. Microsoft and/or its respective suppliers make no representations about the suit- ability of the information contained in the documents and related graphics published as part of the services for any purpose. All such documents and related graphics are provided “as is” without warranty of any kind. Microsoft and/ or its respective suppliers hereby disclaim all warranties and conditions with regard to this information, including all warranties and conditions of merchantability, whether express, implied or statutory, fitness for a particular purpose, title and non-infringement. In no event shall Microsoft and/or its respective suppliers be liable for any special, indi- rect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of information available from the services. The documents and related graphics contained herein could include techni- cal inaccuracies or typographical errors. Changes are periodically added to the information herein. Microsoft and/or its respective suppliers may make improvements and/or changes in the product(s) and/or the program(s) described herein at any time. Partial screen shots may be viewed in full within the software version specified.

Pearson Education Limited KAO Two KAO Park Harlow CM17 9NA United Kingdom

and Associated Companies throughout the world

Visit us on the World Wide Web at: www.pearsonglobaleditions.com

© Pearson Education Limited 2019

The rights of Y. Daniel Liang to be identified as the author of this work have been asserted by him in accordance with the Copyright, Designs and Patents Act 1988.

Authorized adaptation from the United States edition, entitled Introduction to Java Programming and Data Structures, Comprehensive Version, 11th Edition, ISBN 978-0-13-467094-2 by Y. Daniel Liang, published by Pearson Education © 2018.

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without either the prior written permission of the publisher or a license permitting restricted copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6–10 Kirby Street, London EC1N 8TS.

All trademarks used herein are the property of their respective owners. The use of any trademark in this text does not vest in the author or publisher any trademark ownership rights in such trademarks, nor does the use of such trademarks imply any affiliation with or endorsement of this book by such owners.

British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library

10 9 8 7 6 5 4 3 2 1

Typeset by SPi Global ISBN-10: 1-292-22187-9

Printed and bound by Vivar in Malaysia ISBN-13: 978-1-292-22187-8

Senior Vice President Courseware Portfolio Management: Marcia J. Horton

Director, Portfolio Management: Engineering, Computer Science & Global Editions: Julian Partridge

Higher Ed Portfolio Management: Tracy Johnson (Dunkelberger)

Portfolio Management Assistant: Kristy Alaura Managing Content Producer: Scott Disanno Content Producer: Robert Engelhardt Web Developer: Steve Wright Assistant Acquisitions Editor, Global Edition:

Aditee Agarwal Assistant Project Editor, Global Edition: Shaoni

Mukherjee

Manager, Media Production, Global Edition: Vikram Kumar

Senior Manufacturing Controller, Production, Global Edition: Jerry Kataria

Rights and Permissions Manager: Ben Ferrini Manufacturing Buyer, Higher Ed, Lake Side

Communications Inc (LSC): Maura Zaldivar-Garcia Inventory Manager: Ann Lam Marketing Manager: Demetrius Hall Product Marketing Manager: Bram Van Kempen Marketing Assistant: Jon Bryant Cover Designer: Lumina Datamatics Cover Image: Eduardo Rocha/ shutterstock.com Full-Service Project Management: Shylaja Gattupalli,

SPi Global

A01_LIAN1878_11_GE_FM.indd 2 1/2/18 11:57 PM

3

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.

The book is fundamentals first by introducing basic programming concepts and techniques before designing custom classes. The fundamental concepts and techniques of selection statements, loops, methods, and arrays are the foundation for programming. Building this strong foundation prepares students to learn object-oriented programming and advanced Java programming.

This book teaches programming in a problem-driven way that focuses on problem solv- ing rather than syntax. We make introductory programming interesting by using thought- provoking problems in a broad context. The central thread of early chapters is on problem solving. Appropriate syntax and library are introduced to enable readers to write programs for solving the problems. To support the teaching of programming in a problem-driven way, the book provides a wide variety of problems at various levels of difficulty to motivate students. To appeal to students in all majors, the problems cover many application areas, including math, science, business, financial, gaming, animation, and multimedia.

The book seamlessly integrates programming, data structures, and algorithms into one text. It employs a practical approach to teach data structures. We first introduce how to use various data structures to develop efficient algorithms, and then show how to implement these data structures. Through implementation, students gain a deep understanding on the efficiency of data structures and on how and when to use certain data structures. Finally, we design and implement custom data structures for trees and graphs.

The book is widely used in the introductory programming, data structures, and algorithms courses in the universities around the world. This comprehensive version covers fundamen- tals of programming, object-oriented programming, GUI programming, data structures, algo- rithms, concurrency, networking, database, and Web programming. It is designed to prepare students to become proficient Java programmers. A brief version (Introduction to Java Pro- gramming, Brief Version, Eleventh Edition, Global Edition) is available for a first course on programming, commonly known as CS1. The brief version contains the first 18 chapters of the comprehensive version.

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 y.daniel.liang@gmail.com www.pearsonglobaleditions.com/Liang

fundamentals-first

problem-driven

data structures

comprehensive version

brief version

Preface

A01_LIAN1878_11_GE_FM.indd 3 1/2/18 11:57 PM

4 Preface

ACM/IEEE Curricular 2013 and ABET Course Assessment The new ACM/IEEE Computer Science Curricular 2013 defines the Body of Knowledge organized into 18 Knowledge Areas. To help instructors design the courses based on this book, we provide sample syllabi to identify the Knowledge Areas and Knowledge Units. The sample syllabi are for a three semester course sequence and serve as an example for institutional customization. The sample syllabi are accessible from the Instructor Resource Center.

Many of our users are from the ABET-accredited programs. A key component of the ABET accreditation is to identify the weakness through continuous course assessment against the course outcomes. We provide sample course outcomes for the courses and sam- ple exams for measuring course outcomes on the Instructor Resource Center.

What’s New in This Edition? This edition is completely revised in every detail to enhance clarity, presentation, content, examples, and exercises. The major improvements are as follows:

■■ The book’s title is changed to Introduction to Java Programming and Data Structures with new enhancements on data structures. The book uses a practical approach to introduce design, implement, and use data structures and covers all topics in a typical data structures course. Additionally, it provides bonus chapters that cover advanced data structures such as 2-4 trees, B-trees, and red-black trees.

■■ Updated to the latest Java technology. Examples and exercises are improved and simplified by using the new features in Java 8.

■■ 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.

■■ Inner classes, anonymous inner classes, and lambda expressions are covered using practi- cal examples in Chapter 15.

■■ 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.

■■ The forEach method is introduced in Chapter 20 as a simple alternative to the foreach loop for applying an action to each element in a collection.

■■ 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.

■■ Chapter 30 is brand new to introduce aggregate operations for collection streams.

■■ FXML and the Scene Builder visual tool are introduced in Chapter 31.

■■ The Companion Website has been redesigned with new interactive quiz, CheckPoint ques- tions, animations, and live coding.

■■ More than 200 additional programming exercises with solutions are provided to the instructor on the Instructor Resource Center. These exercises are not printed in the text.

A01_LIAN1878_11_GE_FM.indd 4 1/2/18 11:57 PM

Preface 5

Pedagogical Features The book uses the following elements to help students get the most from the material:

■■ The Objectives at the beginning of each chapter list what students should learn from the chapter. This will help them determine whether they have met the objectives after completing the chapter.

■■ The Introduction opens the discussion with a thought-provoking question to motivate the reader to delve into the chapter.

■■ Key Points highlight the important concepts covered in each section.

■■ Check Points provide review questions to help students track their progress as they read through the chapter and evaluate their learning.

■■ Problems and Case Studies, carefully chosen and presented in an easy-to-follow style, teach problem solving and programming concepts. The book uses many small, simple, and stimulating examples to demonstrate important ideas.

■■ The Chapter Summary reviews the important subjects that students should understand and remember. It helps them reinforce the key concepts they have learned in the chapter.

■■ Quizzes are accessible online, grouped by sections, for students to do self-test on programming concepts and techniques.

■■ Programming Exercises are grouped by sections to provide students with opportunities to apply the new skills they have learned on their own. The level of difficulty is rated as easy (no asterisk), moderate (*), hard (**), or challenging (***). The trick of learning program- ming is practice, practice, and practice. To that end, the book provides a great many exer- cises. Additionally, more than 200 programming exercises with solutions are provided to the instructors on the Instructor Resource Center. These exercises are not printed in the text.

■■ 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.

A01_LIAN1878_11_GE_FM.indd 5 1/2/18 11:57 PM

C ha

pt er

3 9

Ja va

Se rv

er F

ac es

C ha

pt er

4 0

R M

I

C ha

pt er

4 1

W eb

S er

vi ce

s

C ha

pt er

4 4

T es

ti ng

U si

ng J

U ni

t

C ha

pt er

3 8

Ja va

Se rv

er P

ag es

C ha

pt er

2 5

B in

ar y

Se ar

ch T

re es

C ha

pt er

2 6

A V

L T

re es

C ha

pt er

2 9

W ei

gh te

d G

ra ph

s an

d A

pp lic

at io

ns

C ha

pt er

2 8

G ra

ph s

an d

A

pp lic

at io

ns

C ha

pt er

2 1

Se ts

a nd

M ap

s

C ha

pt er

2 2

D ev

el op

pi ng

E

f� ci

en t A

lg or

it hm

s

C ha

pt er

1 I

nt ro

du ct

io n

to

C om

pu te

rs , P

ro gr

am s,

a nd

J

av a

C ha

pt er

2 E

le m

en ta

ry

P ro

gr am

m in

g

C ha

pt er

5 L

oo ps

C ha

pt er

7 S

in gl

e- D

im en

si on

al

A rr

ay s

C ha

pt er

8 M

ul ti

di m

en si

on al

A

rr ay

s

C ha

pt er

4 M

at he

m at

ic al

F

un ct

io ns

, C ha

ra ct

er s,

a

nd S

tr in

gs

P ar

t I : F

un da

m en

ta ls

o f

P

ro gr

am m

in g

C ha

pt er

3 S

el ec

ti on

s

C ha

pt er

9 O

bj ec

ts a

nd C

la ss

es

C ha

pt er

1 7

B in

ar y

I/ O

N ot

e: C

ha pt

er s

1– 18

a re

in th

e br

ie f v

er si

on o

f t hi

s bo

ok .

N ot

e: C

ha pt

er s

1– 30

a re

in th

e co

m pr

eh en

si ve

v er

si on

.

N ot

e: C

ha pt

er s

31 –4

4 ar

e bo

nu s

ch ap

te rs

a va

ila bl

e fr

om th

e C

om pa

ni on

W eb

si te

.

C ha

pt er

1 0

T hi

nk in

g in

O bj

ec ts

C ha

pt er

1 1

In he

ri ta

nc e

an d

P

ol ym

or ph

is m

C ha

pt er

1 2

E xc

ep ti

on

H an

dl in

g a

nd T

ex t I

/O

C ha

pt er

1 3

A bs

tr ac

t C la

ss es

a

nd I

nt er

fa ce

s

C ha

pt er

6 M

et ho

ds

P ar

t I I:

O bj

ec t-

O ri

en te

d

P ro

gr am

m in

g

C ha

pt er

3 2

M ul

ti th

re ad

in g

an d

P ar

al le

l P ro

gr am

m in

g

C ha

pt er

3 6

In te

rn at

io na

liz at

io n

C ha

pt er

3 3

N et

w or

ki ng

C ha

pt er

3 4

Ja va

D at

ab as

e

P

ro gr

am m

in g

C ha

pt er

3 5

A dv

an ce

d D

at ab

as e

P ro

gr am

m in

g

C ha

pt er

3 7

Se rv

le ts

P ar

t V : A

dv an

ce d

Ja va

P

ro gr

am m

in g

C ha

pt er

1 4

Ja va

F X

B as

ic s

C ha

pt er

1 5

E ve

nt -D

ri ve

n

P ro

gr am

m in

g an

d

A ni

m at

io ns

C ha

pt er

2 0

L is

ts , S

ta ck

s, Q

ue ue

s,

a nd

P ri

or it

y Q

ue ue

s C

ha pt

er 1

6 Ja

va F

X C

on tr

ol s

a

nd M

ul ti

m ed

ia

C ha

pt er

3 1

A dv

an ce

d J

av aF

X

a nd

F X

M L

P ar

t I II

: G U

I P

ro gr

am m

in g

C ha

pt er

1 8

R ec

ur si

on C

h 7

C ha

pt er

1 9

G en

er ic

s

C ha

pt er

2 4

Im pl

em en

ti ng

L is

ts ,

S

ta ck

s, Q

ue ue

s, a

nd P

ri or

it y

Q

ue ue

s

P ar

t I V

: D at

a St

ru ct

ur es

a nd

A

lg or

it hm

s

C h

13

C h

16

C h

9

C ha

pt er

3 0

A gg

re ga

te O

pe ra

tio ns

an d

C ol

le ct

io n

St re

am s

C ha

pt er

4 2

2- 4

T re

es a

nd B

-

T re

es

C ha

pt er

4 3

R ed

-B la

ck T

re es

C ha

pt er

2 7

H as

hi ng

C ha

pt er

2 3

So rt

in g

6 Preface

A01_LIAN1878_11_GE_FM.indd 6 1/2/18 11:57 PM

Organization of the Book The chapters can be grouped into five parts that, taken together, form a comprehensive introduc- tion to Java programming, data structures and algorithms, and database and Web programming. Because knowledge is cumulative, the early chapters provide the conceptual basis for under- standing programming and guide students through simple examples and exercises; subsequent chapters progressively present Java programming in detail, culminating with the development of comprehensive Java applications. The appendixes contain a mixed bag of topics, including an introduction to number systems, bitwise operations, regular expressions, and enumerated types.

Part I: Fundamentals of Programming (Chapters 1–8)

The first part of the book is a stepping stone, preparing you to embark on the journey of learning Java. You will begin to learn about Java (Chapter 1) and fundamental programming techniques with primitive data types, variables, constants, assignments, expressions, and operators ( Chapter 2), selection statements (Chapter 3), mathematical functions, characters, and strings (Chapter 4), loops (Chapter 5), methods (Chapter 6), and arrays (Chapters 7–8). After Chapter 7, you can jump to Chapter 18 to learn how to write recursive methods for solving inherently recursive problems.

Part II: Object-Oriented Programming (Chapters 9–13, and 17)

This part introduces object-oriented programming. Java is an object-oriented programming language that uses abstraction, encapsulation, inheritance, and polymorphism to provide great flexibility, modularity, and reusability in developing software. You will learn program- ming with objects and classes (Chapters 9–10), class inheritance (Chapter 11), polymorphism ( Chapter 11), exception handling (Chapter 12), abstract classes (Chapter 13), and interfaces (Chapter 13). Text I/O is introduced in Chapter 12 and binary I/O is discussed in Chapter 17.

Part III: GUI Programming (Chapters 14–16 and Bonus Chapter 31)

JavaFX is a new framework for developing Java GUI programs. It is not only useful for developing GUI programs, but also an excellent pedagogical tool for learning object-oriented programming. This part introduces Java GUI programming using JavaFX in Chapters 14–16. Major topics include GUI basics (Chapter 14), container panes (Chapter 14), drawing shapes (Chapter 14), event-driven programming (Chapter 15), animations (Chapter 15), and GUI controls (Chapter 16), and playing audio and video (Chapter 16). You will learn the architecture of JavaFX GUI programming and use the controls, shapes, panes, image, and video to develop useful applications. Chapter 31 covers advanced features in JavaFX.

Part IV: Data Structures and Algorithms (Chapters 18–30 and Bonus Chapters 42–43)

This part covers the main subjects in a typical data structures and algorithms course. Chapter 18 introduces recursion to write methods for solving inherently recursive problems. Chapter 19 presents how generics can improve software reliability. Chapters 20 and 21 introduce the Java Collection Framework, which defines a set of useful API for data structures. Chapter 22 discusses measur- ing algorithm efficiency in order to choose an appropriate algorithm for applications. Chapter 23 describes classic sorting algorithms. You will learn how to implement several classic data struc- tures lists, queues, and priority queues in Chapter 24. Chapters 25 and 26 introduce binary search trees and AVL trees. Chapter 27 presents hashing and implementing maps and sets using hashing. Chapters 28 and 29 introduce graph applications. Chapter 30 introduces aggregate operations for collection streams. The 2-4 trees, B-trees, and red-black trees are covered in Bonus Chapters 42–43.

Part V: Advanced Java Programming (Chapters 32-41, 44)

This part of the book is devoted to advanced Java programming. Chapter 32 treats the use of multithreading to make programs more responsive and interactive and introduces parallel pro- gramming. Chapter 33 discusses how to write programs that talk with each other from different

Preface 7

A01_LIAN1878_11_GE_FM.indd 7 1/2/18 11:57 PM

hosts over the Internet. Chapter 34 introduces the use of Java to develop database projects. Chapter 35 delves into advanced Java database programming. Chapter 36 covers the use of internationalization support to develop projects for international audiences. Chapters 37 and 38 introduce how to use Java servlets and JavaServer Pages to generate dynamic content from Web servers. Chapter 39 introduces modern Web application development using JavaServer Faces. Chapter 40 introduces remote method invocation and Chapter 41 discusses Web ser- vices. Chapter 44 introduces testing Java programs using JUnit.

Appendixes

This part of the book covers a mixed bag of topics. Appendix A lists Java keywords. Appendix B gives tables of ASCII characters and their associated codes in decimal and in hex. Appen- dix C shows the operator precedence. Appendix D summarizes Java modifiers and their usage. Appendix E discusses special floating-point values. Appendix F introduces number systems and conversions among binary, decimal, and hex numbers. Finally, Appendix G introduces bitwise operations. Appendix H introduces regular expressions. Appendix I covers enumerated types.

Java Development Tools You can use a text editor, such as the Windows Notepad or WordPad, to create Java programs and to compile and run the programs from the command window. You can also use a Java development tool, such as NetBeans or Eclipse. These tools support an integrated develop- ment environment (IDE) for developing Java programs quickly. Editing, compiling, building, executing, and debugging programs are integrated in one graphical user interface. Using these tools effectively can greatly increase your programming productivity. NetBeans and Eclipse are easy to use if you follow the tutorials. Tutorials on NetBeans and Eclipse can be found in the supplements on the Companion Website www.pearsonglobaleditions.com/Liang.

Student Resources The Companion Website (www.pearsonglobaleditions.com/Liang) contains the following resources:

■■ Answers to CheckPoint questions

■■ Solutions to majority of even-numbered programming exercises

■■ Source code for the examples in the book

■■ Interactive quiz (organized by sections for each chapter)

■■ Supplements

■■ Debugging tips

■■ Video notes

■■ Algorithm animations

Supplements The text covers the essential subjects. The supplements extend the text to introduce additional topics that might be of interest to readers. The supplements are available from the Companion Website.

IDE tutorials

8 Preface

A01_LIAN1878_11_GE_FM.indd 8 1/2/18 11:57 PM

Instructor Resources The Companion Website, accessible from www.pearsonglobaleditions.com/Liang, contains the following resources:

■■ Microsoft PowerPoint slides with interactive buttons to view full-color, syntax-highlighted source code and to run programs without leaving the slides.

■■ Solutions to a majority of odd-numbered programming exercises.

■■ More than 200 additional programming exercises and 300 quizzes organized by chapters. These exercises and quizzes are available only to the instructors. Solutions to these exercises and quizzes are provided.

■■ Web-based quiz generator. (Instructors can choose chapters to generate quizzes from a large database of more than two thousand questions.)

■■ Sample exams. Most exams have four parts:

■■ Multiple-choice questions or short-answer questions

■■ Correct programming errors

■■ Trace programs

■■ Write programs

■■ Sample exams with ABET course assessment.

■■ Projects. In general, each project gives a description and asks students to analyze, design, and implement the project.

Some readers have requested the materials from the Instructor Resource Center. Please understand that these are for instructors only. Such requests will not be answered.

Online Practice and Assessment with MyProgrammingLab MyProgrammingLab helps students fully grasp the logic, semantics, and syntax of program- ming. Through practice exercises and immediate, personalized feedback, MyProgrammingLab improves the programming competence of beginning students who often struggle with the basic concepts and paradigms of popular high-level programming languages.

A self-study and homework tool, a MyProgrammingLab course consists of hundreds of small practice problems organized around the structure of this textbook. For students, the system auto- matically detects errors in the logic and syntax of their code submissions and offers targeted hints that enable students to figure out what went wrong—and why. For instructors, a comprehensive gradebook tracks correct and incorrect answers and stores the code inputted by students for review.

MyProgrammingLab is offered to users of this book in partnership with Turing’s Craft, the makers of the CodeLab interactive programming exercise system. For a full demonstration, to see feedback from instructors and students, or to get started using MyProgrammingLab in your course, visit www.myprogramminglab.com.

Video Notes We are excited about the new Video Notes feature that is found in this new edition. These videos provide additional help by presenting examples of key topics and showing how to solve problems completely from design through coding. Video Notes are available from www.pearsonglobaleditions.com/Liang.

VideoNote

Preface 9

A01_LIAN1878_11_GE_FM.indd 9 04/01/18 6:28 pm

Algorithm Animations We have provided numerous animations for algorithms. These are valuable pedagogical tools to demonstrate how algorithms work. Algorithm animations can be accessed from the Com- panion Website.

Acknowledgments I would like to thank Armstrong State University for enabling me to teach what I write and for supporting me in writing what I teach. Teaching is the source of inspiration for continuing to improve the book. I am grateful to the instructors and students who have offered comments, suggestions, corrections, and praise. My special thanks go to Stefan Andrei of Lamar Univer- sity and William Bahn of University of Colorado Colorado Springs for their help to improve the data structures part of this book.

This book has been greatly enhanced thanks to outstanding reviews for this and previous edi- tions. The reviewers are: Elizabeth Adams (James Madison University), Syed Ahmed (North Georgia College and State University), Omar Aldawud (Illinois Institute of Technology), Ste- fan Andrei (Lamar University), Yang Ang (University of Wollongong, Australia), Kevin Bierre (Rochester Institute of Technology), Aaron Braskin (Mira Costa High School), David Champion (DeVry Institute), James Chegwidden (Tarrant County College), Anup Dargar (University of North Dakota), Daryl Detrick (Warren Hills Regional High School), Charles Dierbach (Towson Univer- sity), Frank Ducrest (University of Louisiana at Lafayette), Erica Eddy (University of Wisconsin at Parkside), Summer Ehresman (Center Grove High School), Deena Engel (New York University), Henry A. Etlinger (Rochester Institute of Technology), James Ten Eyck (Marist College), Myers Foreman (Lamar University), Olac Fuentes (University of Texas at El Paso), Edward F. Gehringer (North Carolina State University), Harold Grossman (Clemson University), Barbara Guillot (Loui- siana State University), Stuart Hansen (University of Wisconsin, Parkside), Dan Harvey (Southern Oregon University), Ron Hofman (Red River College, Canada), Stephen Hughes (Roanoke Col- lege), Vladan Jovanovic (Georgia Southern University), Deborah Kabura Kariuki (Stony Point High School), Edwin Kay (Lehigh University), Larry King (University of Texas at Dallas), Nana Kofi (Langara College, Canada), George Koutsogiannakis (Illinois Institute of Technology), Roger Kraft (Purdue University at Calumet), Norman Krumpe (Miami University), Hong Lin (DeVry Institute), Dan Lipsa (Armstrong State University), James Madison (Rensselaer Polytechnic Insti- tute), Frank Malinowski (Darton College), Tim Margush (University of Akron), Debbie Masada (Sun Microsystems), Blayne Mayfield (Oklahoma State University), John McGrath (J.P. McGrath Consulting), Hugh McGuire (Grand Valley State), Shyamal Mitra (University of Texas at Austin), Michel Mitri (James Madison University), Kenrick Mock (University of Alaska Anchorage), Frank Murgolo (California State University, Long Beach), Jun Ni (University of Iowa), Benjamin Nystuen (University of Colorado at Colorado Springs), Maureen Opkins (CA State University, Long Beach), Gavin Osborne (University of Saskatchewan), Kevin Parker (Idaho State University), Dale Par- son (Kutztown University), Mark Pendergast (Florida Gulf Coast University), Richard Povinelli (Marquette University), Roger Priebe (University of Texas at Austin), Mary Ann Pumphrey (De Anza Junior College), Pat Roth (Southern Polytechnic State University), Amr Sabry (Indiana Uni- versity), Ben Setzer (Kennesaw State University), Carolyn Schauble (Colorado State University), David Scuse (University of Manitoba), Ashraf Shirani (San Jose State University), Daniel Spiegel (Kutztown University), Joslyn A. Smith (Florida Atlantic University), Lixin Tao (Pace University), Ronald F. Taylor (Wright State University), Russ Tront (Simon Fraser University), Deborah Trytten (University of Oklahoma), Michael Verdicchio (Citadel), Kent Vidrine (George Washington Uni- versity), and Bahram Zartoshty (California State University at Northridge).

It is a great pleasure, honor, and privilege to work with Pearson. I would like to thank Tracy Johnson and her colleagues Marcia Horton, Demetrius Hall, Yvonne Vannatta, Kristy Alaura, Carole Snyder, Scott Disanno, Bob Engelhardt, Shylaja Gattupalli, and their colleagues for organizing, producing, and promoting this project.

As always, I am indebted to my wife, Samantha, for her love, support, and encouragement.

Animation

10 Preface

A01_LIAN1878_11_GE_FM.indd 10 1/2/18 11:57 PM

Acknowledgments for the Global Edition Pearson would like to thank and acknowledge Yvan Maillot (Univresite Haute-Alsace) and Steven Yuwono (National University of Singapore) for contributing to this Global Edition, and Arif Ahmed (National Institute of Technology, Silchar), Annette Bieniusa (University of Kaiserslautern), Shaligram Prajapat (Devi Ahilya Vishwavidyalaya, Indore), and Ram Gopal Raj (University of Malaya) for reviewing this Global Edition.

Preface 11

A01_LIAN1878_11_GE_FM.indd 11 1/2/18 11:57 PM

12

contentS chapter 1 Introduction to computers,

Programs, and Java™ 23 1.1 Introduction 24 1.2 What Is a Computer? 24 1.3 Programming Languages 29 1.4 Operating Systems 31 1.5 Java, the World Wide Web, and Beyond 32 1.6 The Java Language Specification, API, JDK,

JRE, and IDE 33 1.7 A Simple Java Program 34 1.8 Creating, Compiling, and Executing a Java Program 37 1.9 Programming Style and Documentation 40 1.10 Programming Errors 42 1.11 Developing Java Programs Using NetBeans 45 1.12 Developing Java Programs Using Eclipse 47

chapter 2 elementary Programming 55 2.1 Introduction 56 2.2 Writing a Simple Program 56 2.3 Reading Input from the Console 59 2.4 Identifiers 62 2.5 Variables 62 2.6 Assignment Statements and Assignment Expressions 64 2.7 Named Constants 65 2.8 Naming Conventions 66 2.9 Numeric Data Types and Operations 67 2.10 Numeric Literals 70 2.11 Evaluating Expressions and Operator Precedence 72 2.12 Case Study: Displaying the Current Time 74 2.13 Augmented Assignment Operators 76 2.14 Increment and Decrement Operators 77 2.15 Numeric Type Conversions 79 2.16 Software Development Process 81 2.17 Case Study: Counting Monetary Units 85 2.18 Common Errors and Pitfalls 87

chapter 3 Selections 97 3.1 Introduction 98 3.2 boolean Data Type 98 3.3 if Statements 100 3.4 Two-Way if-else Statements 102 3.5 Nested if and Multi-Way if-else Statements 103 3.6 Common Errors and Pitfalls 105 3.7 Generating Random Numbers 109 3.8 Case Study: Computing Body Mass Index 111 3.9 Case Study: Computing Taxes 112 3.10 Logical Operators 115 3.11 Case Study: Determining Leap Year 119 3.12 Case Study: Lottery 120 3.13 switch Statements 122

A01_LIAN1878_11_GE_FM.indd 12 1/2/18 11:57 PM

3.14 Conditional Operators 125 3.15 Operator Precedence and Associativity 126 3.16 Debugging 128

chapter 4 mathematical functions, characters, and Strings 141

4.1 Introduction 142 4.2 Common Mathematical Functions 142 4.3 Character Data Type and Operations 147 4.4 The String Type 152 4.5 Case Studies 161 4.6 Formatting Console Output 167

chapter 5 Loops 181 5.1 Introduction 182 5.2 The while Loop 182 5.3 Case Study: Guessing Numbers 185 5.4 Loop Design Strategies 188 5.5 Controlling a Loop with User Confirmation or a Sentinel Value 190 5.6 The do-while Loop 192 5.7 The for Loop 195 5.8 Which Loop to Use? 198 5.9 Nested Loops 200 5.10 Minimizing Numeric Errors 202 5.11 Case Studies 204 5.12 Keywords break and continue 208 5.13 Case Study: Checking Palindromes 211 5.14 Case Study: Displaying Prime Numbers 213

chapter 6 methods 227 6.1 Introduction 228 6.2 Defining a Method 228 6.3 Calling a Method 230 6.4 void vs. Value-Returning Methods 233 6.5 Passing Parameters by Values 236 6.6 Modularizing Code 239 6.7 Case Study: Converting Hexadecimals to Decimals 241 6.8 Overloading Methods 243 6.9 The Scope of Variables 246 6.10 Case Study: Generating Random Characters 247 6.11 Method Abstraction and Stepwise Refinement 249

chapter 7 Single-dimensional arrays 269 7.1 Introduction 270 7.2 Array Basics 270 7.3 Case Study: Analyzing Numbers 277 7.4 Case Study: Deck of Cards 278 7.5 Copying Arrays 280 7.6 Passing Arrays to Methods 281 7.7 Returning an Array from a Method 284 7.8 Case Study: Counting the Occurrences of Each Letter 285 7.9 Variable-Length Argument Lists 288 7.10 Searching Arrays 289 7.11 Sorting Arrays 293

Contents 13

A01_LIAN1878_11_GE_FM.indd 13 1/2/18 11:57 PM

7.12 The Arrays Class 294 7.13 Command-Line Arguments 296

chapter 8 multidimensional arrays 311 8.1 Introduction 312 8.2 Two-Dimensional Array Basics 312 8.3 Processing Two-Dimensional Arrays 315 8.4 Passing Two-Dimensional Arrays to Methods 317 8.5 Case Study: Grading a Multiple-Choice Test 318 8.6 Case Study: Finding the Closest Pair 320 8.7 Case Study: Sudoku 322 8.8 Multidimensional Arrays 325

chapter 9 objects and classes 345 9.1 Introduction 346 9.2 Defining Classes for Objects 346 9.3 Example: Defining Classes and Creating Objects 348 9.4 Constructing Objects Using Constructors 353 9.5 Accessing Objects via Reference Variables 354 9.6 Using Classes from the Java Library 358 9.7 Static Variables, Constants, and Methods 361 9.8 Visibility Modifiers 366 9.9 Data Field Encapsulation 368 9.10 Passing Objects to Methods 371 9.11 Array of Objects 375 9.12 Immutable Objects and Classes 377 9.13 The Scope of Variables 379 9.14 The this Reference 380

chapter 10 object-oriented thinking 389 10.1 Introduction 390 10.2 Class Abstraction and Encapsulation 390 10.3 Thinking in Objects 394 10.4 Class Relationships 397 10.5 Case Study: Designing the Course Class 400 10.6 Case Study: Designing a Class for Stacks 402 10.7 Processing Primitive Data Type Values as Objects 404 10.8 Automatic Conversion between Primitive Types

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

Assignment Hut
Innovative Writer
Fatimah Syeda
Financial Solutions Provider
Helping Hand
Professional Coursework Help
Writer Writer Name Offer Chat
Assignment Hut

ONLINE

Assignment Hut

I am a professional and experienced writer and I have written research reports, proposals, essays, thesis and dissertations on a variety of topics.

$35 Chat With Writer
Innovative Writer

ONLINE

Innovative Writer

I have assisted scholars, business persons, startups, entrepreneurs, marketers, managers etc in their, pitches, presentations, market research, business plans etc.

$46 Chat With Writer
Fatimah Syeda

ONLINE

Fatimah Syeda

I have read your project description carefully and you will get plagiarism free writing according to your requirements. Thank You

$15 Chat With Writer
Financial Solutions Provider

ONLINE

Financial Solutions Provider

I find your project quite stimulating and related to my profession. I can surely contribute you with your project.

$17 Chat With Writer
Helping Hand

ONLINE

Helping Hand

This project is my strength and I can fulfill your requirements properly within your given deadline. I always give plagiarism-free work to my clients at very competitive prices.

$25 Chat With Writer
Professional Coursework Help

ONLINE

Professional Coursework Help

This project is my strength and I can fulfill your requirements properly within your given deadline. I always give plagiarism-free work to my clients at very competitive prices.

$39 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Scout shop leicester forest east - How to improve plant utilization in capsim - John lewis bonus 2009 - Complete nes collection list - Area of cylinder without top and bottom - Wm cohen & sons inc - History 10 - Why technology favors tyranny essay - N4455 change theory project - Lockwood 002 digital deadlatch - Shield row primary school - Edit a paragraph worksheet - Diverging lens ray diagram worksheet - Love and hate relationship psychology - Why are cells so small - Warner company's year end unadjusted trial balance shows accounts receivable - How to enchant a sieve mesh - Response - What is polarity test - Amp flexible super fund - American gothic analysis essay - Responses - What gases are exchanged by an animal with its environment - Determine the missing amounts for three different situations - Give me liberty fifth edition pdf - Ba15s bulb cross reference - Elevation of privilege eop card game - Puffing billy route map - Customer complaint role play script - Four elements of fitness programs issa - American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.). Chapter 3 and 4 - Penetration test proposal deliverable 1 rules of engagement - Lafha reasonable amounts 2021 - NURSING (PEDIATRICS) - Intercultural effectiveness scale - Bsbpmg522 assessment 1 answers - How many wives does okonkwo have - Electrical wiring symbols chart - Kubler ross change curve - Sowilo community high school - Journal Entry - Please consider the Leonardt Essay and at least one of the relevant "Is College Worth It" - Dramatic hip hop instrumental rebel america inc - NEED IN 15 HOURS or LESS - Biology chapter 5 the working cell worksheet answers - Average weight of a round bale of hay - Holes chapter questions multiple choice - Special education and learning disabilities through social science - Reasons not to have cellphones in school - Ops 571 week 5 six sigma yellow belt training ii - Stoichiometry lab vinegar and baking soda answer key - Business ethics - Claes oldenburg burger sculpture - Cultural diversity what role does it play in patient safety - Matt rose makeup artist - Leadership in Healthcare Organization W5 Project - Bus timetable central coast - Introduction to type isabel briggs myers pdf - Anyone who had a heart by phil stephens answers - Greenwood airvac cv2gip manual - Quize - Aecc global philippines reviews - Health Screenings and Prevention Assignment - X 6y 12 solve for y - Java fundamentals a comprehensive introduction by herbert schildt pdf download - Your textbook recommends using visual aids to make statistics easier for listeners to comprehend. - Accumulated depreciation and depreciation expense are classified respectively as - Cultural construction of gender - Geology Week 3 - Procedure for preparation of methyl orange - How does blood doping work - Journalize the transactions including explanations - Cross a heterozygous running - Resultant force bbc bitesize - Cardinia council fire restrictions - Trail of the green blazer characters - All the queen's horses release date - Prof dan healy private clinic - Australian airforce cadets uniform - Model the cardinalities of the following business policies - Electrical units and symbols - Wiify - ENGLISH writing - Deutsche bank leipzig 04024 - 400 word blog project soc350 - 26l of the a - Discussion - Clinical reasoning cycle definition - All instruments in the percussion family - Politics - Igcse english second language past papers reading and writing 0511 - Where to find crn number - Malcolm x learning to read answers - Blank training matrix template - Determining the ksp of calcium hydroxide lab calculations - Fear in the year of wonders - Foot posture index reliability - Global expansion project - Unnatural balance accounting - Isometric perspective art definition