Starting Out With Java: From Control Structures through Objects

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Tony Gaddis
Edition: 7
Publisher: Pearson Education
Year: 2019

Language: English
City: NY
Tags: Java

Starting Out With Java ™ From Control Structures through Objects
Starting Out With Java ™ From Control Structures through Objects
Contents in Brief
Contents
Preface
Control Structures First, Then Objects
Changes in the Seventh Edition
Organization of the Text
Brief Overview of Each Chapter
Features of the Text
Supplements
About the Author
Chapter 1 Introduction to Computers and Java
Topics
1.1 Introduction
1.2 Why Program?
1.3 Computer Systems: Hardware and Software
Hardware
The CPU
Main Memory
Secondary Storage
Input Devices
Output Devices
Software
Checkpoint
1.4 Programming Languages
What Is a Program?
A History of Java
1.5 What Is a Program Made Of?
Language Elements
Key Words (Reserved Words)
Programmer-Defined Names
Operators
Punctuation
Lines and Statements
Variables
The Compiler and the Java Virtual Machine
Portability
Java Software Editions
Compiling and Running a Java Program
Integrated Development Environments
Checkpoint
1.6 The Programming Process
Software Engineering
Checkpoint
1.7 Object-Oriented Programming
Checkpoint
Review Questions and Exercises
Multiple Choice
Find the Error
Algorithm Workbench
Predict the Result
Short Answer
Programming Challenge
1. Your First Java Program
If You Are Using the JDK at the Command Prompt:
If You Are Using an IDE:
Chapter 2 Java Fundamentals
Topics
2.1 The Parts of a Java Program
Checkpoint
2.2 The print and println Methods, and the Java API
2.3 Variables and Literals
Displaying Multiple Items with the + Operator
Be Careful with Quotation Marks
More about Literals
Identifiers
Class Names
Checkpoint
2.4 Primitive Data Types
The Integer Data Types
Integer Literals
Floating-Point Data Types
Floating-Point Literals
Scientific and E Notation
The boolean Data Type
The char Data Type
Unicode
Variable Assignment and Initialization
Variables Hold Only One Value at a Time
Checkpoint
2.5 Arithmetic Operators
Integer Division
Operator Precedence
Grouping with Parentheses
The Math Class
The Math.pow Method
The Math.sqrt Method
Checkpoint
2.6 Combined Assignment Operators
Checkpoint
2.7 Conversion between Primitive Data Types
Mixed Integer Operations
Other Mixed Mathematical Expressions
Checkpoint
2.8 Creating Named Constants with final
2.9 The String Class
Objects Are Created from Classes
The String Class
Primitive Type Variables and Class Type Variables
Creating a String Object
Checkpoint
2.10 Scope
2.11 Comments
2.12 Programming Style
2.13 Reading Keyboard Input
Reading a Character
Mixing Calls to nextLine with Calls to Other Scanner Methods
2.14 Dialog Boxes
Displaying Message Dialogs
Displaying Input Dialogs
An Example Program
Converting String Input to Numbers
Checkpoint
2.15 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Predict the Output
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Name, Age, and Annual Income
2. Name and Initials
3. Personal Information
4. Star Pattern
5. Sales Prediction
6. Land Calculation
7. Sales Tax
8. Cookie Calories
9. Miles-per-Gallon
10. Test Average
11. Circuit Board Profit
12. String Manipulator
13. Restaurant Bill
14. Male and Female Percentages
15. Stock Commission
16. Energy Drink Consumption
17. Ingredient Adjuster
18. Word Game
19. Stock Transaction Program
20. Planting Grapevines
21. Compound Interest
Chapter 3 Decision Structures
Topics
3.1 The if Statement
Using Relational Operators to Form Conditions
Putting It All Together
Programming Style and the if Statement
Be Careful with Semicolons
Having Multiple Conditionally Executed Statements
Flags
Comparing Characters
Checkpoint
3.2 The if-else Statement
Checkpoint
3.3 Nested if Statements
3.4 The if-else-if Statement
3.5 Logical Operators
The Precedence of Logical Operators
Checking Numeric Ranges with Logical Operators
Checkpoint
3.6 Comparing String Objects
Ignoring Case in String Comparisons
Checkpoint
3.7 More about Variable Declaration and Scope
3.8 The Conditional Operator (Optional)
Checkpoint
3.9 The switch Statement
Checkpoint
3.10 Displaying Formatted Output with System.out.printf and String.format
Format Specifier Syntax
Precision
Specifying a Minimum Field Width
Combining Minimum Field Width and Precision in the Same Format Specifier
Flags
Comma Separators
Padding Numbers with Leading Zeros
Left-Justifying Numbers
Formatting String Arguments
The String.format Method
Checkpoint
3.11 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Roman Numerals
2. Magic Dates
3. Body Mass Index
4. Test Scores and Grade
5. Mass and Weight
6. Time Calculator
7. Sorted Names
8. Software Sales
9. Shipping Charges
10. Fat Gram Calculator
11. Running the Race
12. The Speed of Sound
13. Mobile Service Provider
14. Mobile Service Provider, Part 2
15. Bank Charges
16. Book Club Points
17. Wi-Fi Diagnostic Tree
18. Restaurant Selector
Chapter 4 Loops and Files
Topics
4.1 The Increment and Decrement Operators
The Difference between Postfix and Prefix Modes
Checkpoint
4.2 The while Loop
The while Loop Is a Pretest Loop
Infinite Loops
Don’t Forget the Braces with a Block of Statements
Programming Style and the while Loop
Checkpoint
4.3 Using the while Loop for Input Validation
Checkpoint
4.4 The do-while Loop
4.5 The for Loop
The for Loop Is a Pretest Loop
Avoid Modifying the Control Variable in the Body of the for Loop
Other Forms of the Update Expression
Declaring a Variable in the for Loop’s Initialization Expression
Creating a User Controlled for Loop
Using Multiple Statements in the Initialization and Update Expressions
Checkpoint
4.6 Running Totals and Sentinel Values
Using a Sentinel Value
Checkpoint
4.7 Nested Loops
4.8 The break and continue Statements (Optional)
4.9 Deciding Which Loop to Use
4.10 Introduction to File Input and Output
Using the PrintWriter Class to Write Data to a File
More about the PrintWriter Class’s println Method
The PrintWriter Class’s print Method
Adding a throws Clause to the Method Header
An Example Program
Review
Appending Data to a File
Specifying the File Location
Reading Data from a File
Reading Lines from a File with the nextLine Method
Adding a throws Clause to the Method Header
Detecting the End of a File
Reading Primitive Values from a File
Review
Checking for a File’s Existence
Checkpoint
4.11 Generating Random Numbers with the Random Class
Checkpoint
4.12 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Sum of Numbers
2. Distance Traveled
3. Distance File
4. Pennies for Pay
5. Letter Counter
6. File Letter Counter
7. Hotel Occupancy
8. Average Rainfall
9. Population
10. Largest and Smallest
11. Celsius to Fahrenheit Table
12. Bar Chart
13. File Head Display
14. Line Numbers
15. Uppercase File Converter
16. Budget Analysis
17. Random Number Guessing Game
18. Random Number Guessing Game Enhancement
19. ESP Game
20. Square Display
21. Dice Game
22. Slot Machine Simulation
23. Personal Web Page Generator
Chapter 5 Methods
Topics
5.1 Introduction to Methods
void Methods and Value-Returning Methods
Defining a void Method
Calling a Method
Layered Method Calls
Using Documentation Comments with Methods
Checkpoint
5.2 Passing Arguments to a Method
Argument and Parameter Data Type Compatibility
Parameter Variable Scope
Passing Multiple Arguments
Arguments Are Passed by Value
Passing Object References to a Method
Using the @param Tag in Documentation Comments
Checkpoint
5.3 More about Local Variables
Local Variable Lifetime
Initializing Local Variables with Parameter Values
5.4 Returning a Value from a Method
Defining a Value-Returning Method
Calling a Value-Returning Method
Using the @return Tag in Documentation Comments
Returning a boolean Value
Returning a Reference to an Object
Checkpoint
5.5 Problem Solving with Methods
Calling Methods That Throw Exceptions
5.6 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. showChar Method
2. Retail Price Calculator
3. Rectangle Area—Complete the Program
4. Paint Job Estimator
5. Falling Distance
6. Celsius Temperature Table
7. Test Average and Grade
8. Conversion Program
9. Distance Traveled Modification
10. Stock Profit
11. Multiple Stock Sales
12. Kinetic Energy
13. isPrime Method
14. Prime Number List
15. Even/Odd Counter
16. Present Value
17. Rock, Paper, Scissors Game
18. ESP Game
Chapter 6 A First Look at Classes
Topics
6.1 Objects and Classes
Classes: Where Objects Come From
Classes in the Java API
Primitive Variables vs. Objects
Checkpoint
6.2 Writing a Simple Class, Step by Step
Writing the Code for a Class
Writing the Code for the Class Fields
Writing the setLength Method
Writing the setWidth Method
Writing the getLength and getWidth Methods
Writing the getArea Method
Accessor and Mutator Methods
The Importance of Data Hiding
Avoiding Stale Data
Showing Access Specification in UML Diagrams
Data Type and Parameter Notation in UML Diagrams
Layout of Class Members
Checkpoint
6.3 Instance Fields and Methods
Checkpoint
6.4 Constructors
Showing Constructors in a UML Diagram
Uninitialized Local Reference Variables
The Default Constructor
Writing Your Own No-Arg Constructor
The String Class Constructor
Checkpoint
6.5 Passing Objects as Arguments
6.6 Overloading Methods and Constructors
The BankAccount Class
Overloaded Methods Make Classes More Useful
6.7 Scope of Instance Fields
Shadowing
Checkpoint
6.8 Packages and import Statements
Explicit and Wildcard import Statements
The java.lang Package
Other API Packages
6.9 Focus on Object-Oriented Design: Finding the Classes and Their Responsibilities
Finding the Classes
Writing a Description of the Problem Domain
Identifying All of the Nouns
Refining the List of Nouns
1. Some of the nouns really mean the same thing.
2. Some nouns might represent items that we do not need to be concerned with in order to solve the problem.
3. Some of the nouns might represent objects, not classes.
4. Some of the nouns might represent simple values that can be stored in a primitive variable and do not require a class.
Identifying a Class’s Responsibilities
The Customer class
The Car Class
The ServiceQuote Class
This Is Only the Beginning
Checkpoint
6.10 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Employee Class
2. Car Class
3. Personal Information Class
4. RetailItem Class
5. Payroll Class
6. TestScores Class
7. Circle Class
8. Temperature Class
9. Days in a Month
10. A Game of Twenty-One
11. Freezing and Boiling Points
12. SavingsAccount Class
13. Deposit and Withdrawal Files
14. Patient Charges
15. Dice Game
16. Roulette Wheel Colors
17. Coin Toss Simulator
18. Tossing Coins for a Dollar
19. Fishing Game Simulation
Chapter 7 Arrays and the ArrayList Class
Topics
7.1 Introduction to Arrays
Accessing Array Elements
Inputting and Outputting Array Contents
Java Performs Bounds Checking
Watch Out for Off-by-One Errors
Array Initialization
Alternate Array Declaration Notation
Checkpoint
7.2 Processing Array Elements
Array Length
The Enhanced for Loop
The Enhanced for Loop versus the Traditional for Loop
Letting the User Specify an Array’s Size
Reassigning Array Reference Variables
Copying Arrays
Checkpoint
7.3 Passing Arrays as Arguments to Methods
Checkpoint
7.4 Some Useful Array Algorithms and Operations
Comparing Arrays
Summing the Values in a Numeric Array
Getting the Average of the Values in a Numeric Array
Finding the Highest and Lowest Values in a Numeric Array
The SalesData Class
Partially Filled Arrays
Working with Arrays and Files
7.5 Returning Arrays from Methods
7.6 String Arrays
Calling String Methods from an Array Element
Checkpoint
7.7 Arrays of Objects
Checkpoint
7.8 The Sequential Search Algorithm
7.9 Two-Dimensional Arrays
Initializing a Two-Dimensional Array
The length Field in a Two-Dimensional Array
Displaying All the Elements of a Two-Dimensional Array
Summing All the Elements of a Two-Dimensional Array
Summing the Rows of a Two-Dimensional Array
Summing the Columns of a Two-Dimensional Array
Passing Two-Dimensional Arrays to Methods
Ragged Arrays
7.10 Arrays with Three or More Dimensions
Checkpoint
7.11 The Selection Sort and the Binary Search Algorithms
The Selection Sort Algorithm
The Binary Search Algorithm
Checkpoint
7.12 Command-Line Arguments and Variable-Length Argument Lists
Command-Line Arguments
Variable-Length Argument Lists
7.13 The ArrayList Class
Creating and Using an ArrayList Object
Using the Enhanced for Loop with an ArrayList
The ArrayList Class’s toString method
Removing an Item from an ArrayList
Inserting an Item
Replacing an Item
Capacity
Storing Your Own Objects in an ArrayList
Using the Diamond Operator for Type Inference
Checkpoint
7.14 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Rainfall Class
2. Payroll Class
3. Charge Account Validation
4. Charge Account Modification
5. Larger Than n
6. Driver’s License Exam
7. Magic 8 Ball
8. Grade Book
9. Grade Book Modification
10. Average Steps Taken
11. Array Operations
12. 1994 Gas Prices
13. Sorted List of 1994 Gas Prices
14. Name Search
15. Population Data
16. World Series Champions
17. 2D Array Operations
18. Phone Book ArrayList
19. Trivia Game
20. Lo Shu Magic Square
Chapter 8 A Second Look at Classes and Objects
Topics
8.1 Static Class Members
A Quick Review of Instance Fields and Instance Methods
Static Members
Static Fields
Static Methods
Checkpoint
8.2 Passing Objects as Arguments to Methods
8.3 Returning Objects from Methods
8.4 The toString Method
8.5 Writing an equals Method
8.6 Methods That Copy Objects
Copy Constructors
8.7 Aggregation
Aggregation in UML Diagrams
Security Issues with Aggregate Classes
Perform Deep Copies When Creating Field Objects
Return Copies of Field Objects, Not the Originals
Avoid Using null References
8.8 The this Reference Variable
Using this to Overcome Shadowing
Using this to Call an Overloaded Constructor from Another Constructor
Checkpoint
8.9 Enumerated Types
Enumerated Types Are Specialized Classes
Switching On an Enumerated Type
Checkpoint
8.10 Garbage Collection
The finalize Method
8.11 Focus on Object-Oriented Design: Class Collaboration
Determining Class Collaborations with CRC Cards
8.12 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Area Class
2. BankAccount Class Copy Constructor
3. Carpet Calculator
4. LandTract Class
5. Month Class
6. CashRegister Class
7. Sales Receipt File
8. Parking Ticket Simulator
9. Geometry Calculator
10. Car Instrument Simulator
11. First to One Game
12. Heads or Tails Game
Chapter 9 Text Processing and More about Wrapper Classes
Topics
9.1 Introduction to Wrapper Classes
9.2 Character Testing and Conversion with the Character Class
Character Case Conversion
Checkpoint
9.3 More String Methods
Searching for Substrings
The startsWith and endsWith Methods
The regionMatches Methods
Finding Characters with the indexOf and lastIndexOf Methods
Finding Substrings with the indexOf and lastIndexOf Methods
Extracting Substrings
The substring Methods
The getChars and toCharArray Methods
Methods That Return a Modified String
The Static valueOf Methods
Checkpoint
9.4 The StringBuilder Class
The StringBuilder Constructors
Other StringBuilder Methods
The append Methods
The insert Methods
The replace Method
The delete, deleteCharAt, and setCharAt Methods
The toString Method
Checkpoint
9.5 Tokenizing Strings
9.6 Wrapper Classes for the Numeric Data Types
The Static toString Methods
The toBinaryString, toHexString, and toOctalString Methods
The MIN_VALUE and MAX_VALUE Constants
Autoboxing and Unboxing
Checkpoint
9.7 Focus on Problem Solving: The TestScoreReader Class
9.8 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Backward String
2. Word Counter
3. Sentence Capitalizer
4. Vowels and Consonants
5. Password Verifier
6. Telemarketing Phone Number List
7. Check Writer
8. Sum of Numbers in a String
9. Sum of Digits in a String
10. Word Counter
11. Sales Analysis
12. Miscellaneous String Operations
13. Alphabetic Telephone Number Translator
14. Word Separator
15. Pig Latin
16. Morse Code Converter
17. Lottery Statistics
18. Gas Prices
Chapter 10 Inheritance
Topics
10.1 What Is Inheritance?
Generalization and Specialization
Inheritance and the “Is a” Relationship
Fields:
Methods:
Inheritance in UML Diagrams
The Superclass’s Constructor
Inheritance Does Not Work in Reverse
Checkpoint
10.2 Calling the Superclass Constructor
When the Superclass Has No Default or No-Arg Constructors
Summary of Constructor Issues in Inheritance
Checkpoint
10.3 Overriding Superclass Methods
Overloading versus Overriding
Preventing a Method from Being Overridden
Checkpoint
10.4 Protected Members
Package Access
Checkpoint
10.5 Chains of Inheritance
Class Hierarchies
10.6 The Object Class
Checkpoint
10.7 Polymorphism
Polymorphism and Dynamic Binding
The “Is-a” Relationship Does Not Work in Reverse
The instanceof Operator
Checkpoint
10.8 Abstract Classes and Abstract Methods
Abstract Classes in UML
Checkpoint
10.9 Interfaces
An Interface is a Contract
Fields in Interfaces
Implementing Multiple Interfaces
Interfaces in UML
Default Methods
Polymorphism and Interfaces
Checkpoint
10.10 Anonymous Inner Classes
10.11 Functional Interfaces and Lambda Expressions
10.12 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Employee and ProductionWorker Classes
2. ShiftSupervisor Class
3. TeamLeader Class
4.Essay Class
5. Course Grades
6. Analyzable Interface
7. Person and Customer Classes
8. PreferredCustomer Class
9. BankAccount and SavingsAccount Classes
10. Ship, CruiseShip, and CargoShip Classes
Chapter 11 Exceptions and Advanced File I/O
Topics
11.1 Handling Exceptions
Exception Classes
Handling an Exception
Retrieving the Default Error Message
Polymorphic References to Exceptions
Using Multiple catch Clauses to Handle Multiple Exceptions
Using Exception Handlers to Recover from Errors
Handle Each Exception Only Once in a try Statement
The finally Clause
The Stack Trace
Handling Multiple Exceptions with One catch Clause
When an Exception Is Not Caught
Checked and Unchecked Exceptions
Checkpoint
11.2 Throwing Exceptions
Creating Your Own Exception Classes
Using the @exception Tag in Documentation Comments
Checkpoint
11.3 Advanced Topics: Binary Files, Random Access Files, and Object Serialization
Binary Files
Writing Data to a Binary File
Reading Data from a Binary File
Writing and Reading Strings
Appending Data to an Existing Binary File
Random Access Files
Reading and Writing with the RandomAccessFile Class
The File Pointer
Object Serialization
Serializing Aggregate Objects
Checkpoint
11.4 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. TestScores Class
2. TestScores Class Custom Exception
3. RetailItem Exceptions
4. Month Class Exceptions
5. Payroll Class Exceptions
6. FileArray Class
7. File Encryption Filter
8. File Decryption Filter
9. TestScores Modification for Serialization
10. Exception Project
Chapter 12 JavaFX: GUI Programming and Basic Controls
Topics
12.1 Graphical User Interfaces
Event-Driven GUI Programs
Checkpoint
12.2 Introduction to JavaFX
Controls
Stages and Scenes
The Application Class
Checkpoint
12.3 Creating Scenes
Creating Controls
Creating Layout Containers
Creating a Scene Object
Adding the Scene Object to the Stage
Setting the Size of the Scene
Aligning Controls in an HBox Layout Container
Checkpoint
12.4 Displaying Images
Loading Images from an Internet Location
Setting the Size of an Image
Preserving the Image’s Aspect Ratio
Changing an ImageView’s Image
Checkpoint
12.5 More about the HBox, VBox, and GridPane Layout Containers
The HBox Layout Container
Spacing
Padding
The VBox Layout Container
The GridPane Layout Container
Using Multiple Layout Containers in the Same Screen
Checkpoint
12.6 Button Controls and Events
Handling Events
Writing Event Handlers
Registering an Event Handler
Checkpoint
12.7 Reading Input with TextField Controls
Checkpoint
12.8 Using Anonymous Inner Classes and Lambda ­Expressions to Handle Events
Using Anonymous Inner Classes to Create Event Handlers
Using Lambda Expressions to Create Event Handlers
Checkpoint
12.9 The BorderPane Layout Container
Checkpoint
12.10 The ObservableList Interface
12.11 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Latin Translator
2. Name Formatter
3. Tip, Tax, and Total
4. Property Tax
5. Heads or Tails
6. Dice Simulator
7. Travel Expenses
8. Joe’s Automotive
9. Tic-Tac-Toe Simulator
10. Slot Machine Simulation
Chapter 13 JavaFX: Advanced Controls
Topics
13.1 Styling JavaFX Applications with CSS
Type Selector Names
Style Properties
Applying a Stylesheet to a JavaFX Application
Applying Styles to the Root Node
Specifying Multiple Selectors in the Same Style Definition
Working with Colors
Named Colors
Creating a Custom Style Class Name
ID Selectors
Inline Style Rules
Checkpoint
13.2 RadioButton Controls
Determining in Code Whether a RadioButton Is Selected
Selecting a RadioButton in Code
Responding to RadioButton Clicks
Checkpoint
13.3 CheckBox Controls
Determining in Code Whether a CheckBox Is Selected
Selecting a CheckBox in Code
Responding to CheckBox Clicks
Checkpoint
13.4 ListView Controls
Retrieving the Selected Item
Retrieving the Index of the Selected Item
Responding to Item Selection with an Event Handler
Adding Items versus Setting Items
Initializing a ListView with an Array or an ArrayList
Selection Modes
Retrieving Multiple Selected Items
Working With the Elements of an ObservableList
Converting an ObservableList to an Array
Using Code to Select an Item in a ListView
ListView Orientation
Creating ListViews of Objects Other Than String
Checkpoint
13.5 ComboBox Controls
Retrieving the Selected Item
Responding to ComboBox Item Selection with an Event Handler
Editable ComboBoxes
Checkpoint
13.6 Slider Controls
Checkpoint
13.7 TextArea Controls
Checkpoint
13.8 Menus
Assigning Mnemonics to Menu Items
Checkpoint
13.9 The FileChooser Class
Displaying a FileChooser Dialog Box
Checkpoint
13.10 Using Console Output to Debug a GUI Application
13.11 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Dorm and Meal Plan Calculator
2. Skateboard Designer
3. Conference Registration System
4. Smartphone Packages
5. Shopping Cart System
Chapter 14 JavaFX: Graphics, Effects, and Media
Topics
14.1 Drawing Shapes
The Screen Coordinate System
The Shape Class and Its Subclasses
The Line Class
Changing the Stroke Color
The Circle Class
The Rectangle Class
The Ellipse Class
The Arc Class
The Polygon Class
The Polyline Class
The Text Class
Rotating Nodes
Scaling Nodes
Checkpoint
14.2 Animation
The TranslateTransition Class
The RotateTransition Class
The ScaleTransition Class
The StrokeTransition Class
The FillTransition Class
The FadeTransition Class
Controlling the Animation
Specifying an Interpolator
Checkpoint
14.3 Effects
The DropShadow Class
The InnerShadow Class
The ColorAdjust Class
The BoxBlur, GaussianBlur, and MotionBlur Classes
The BoxBlur Class
The GaussianBlur Class
The MotionBlur Class
The SepiaTone Class
The Glow Class
The Reflection Class
Combining Effects
Checkpoint
14.4 Playing Sound Files
Registering an EndOfMedia Event Handler
Checkpoint
14.5 Playing Videos
Checkpoint
14.6 Handling Key Events
Using an Anonymous Inner Class to Register a Key Event Handler to the Scene
Using a Lambda Expression to Register a Key Event Handler to the Scene
Checkpoint
14.7 Handling Mouse Events
14.8 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Algorithm Workbench
Short Answer
Programming Challenges
1. This Old House
2. Tree Age
3. Hollywood Star
4. Vehicle Outline
5. Solar System
6. Opacity Adjuster
7. Color Adjuster
8. Mouse Rollover
9. Coin Toss
10. Lunar Lander
11. Change for a Dollar Game
12. Rock, Paper, Scissors Game
Chapter 15 Recursion
Topics
15.1 Introduction to Recursion
15.2 Solving Problems with Recursion
Direct and Indirect Recursion
Checkpoint
15.3 Examples of Recursive Methods
Summing a Range of Array Elements with Recursion
Drawing Concentric Circles
The Fibonacci Series
Finding the Greatest Common Divisor
15.4 A Recursive Binary Search Method
15.5 The Towers of Hanoi
15.6 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Recursive Multiplication
2. isMember Method
3. String Reverser
4. maxElement Method
5. Palindrome Detector
6. Character Counter
7. Recursive Power Method
8. Sum of Numbers
9. Ackermann’s Function
10. Recursive Population Class
Chapter 16 Databases
Topics
16.1 Introduction to Database Management Systems
JDBC
SQL
Using a DBMS
Java DB and Apache Derby
Creating the CoffeeDB Database
Connecting to the CoffeeDB Database
Connecting to a Password-Protected Database
Checkpoint
16.2 Tables, Rows, and Columns
Column Data Types
Primary Keys
Checkpoint
16.3 Introduction to the SQL SELECT Statement
Passing an SQL Statement to the DBMS
Getting a Row from the ResultSet Object
Getting Columns in a ResultSet Row
More about the SELECT Statement
Specifying Search Criteria with the WHERE Clause
String Comparisons in a SELECT Statement
Using the LIKE Operator
Using AND and OR
Sorting the Results of a SELECT Query
Mathematical Functions
Checkpoint
16.4 Inserting Rows
Inserting Rows with JDBC
Checkpoint
16.5 Updating and Deleting Existing Rows
Updating Rows with JDBC
Deleting Rows with the DELETE Statement
Deleting Rows with JDBC
Checkpoint
16.6 Creating and Deleting Tables
Removing a Table with the DROP TABLE Statement
Checkpoint
16.7 Creating a New Database with JDBC
16.8 Scrollable Result Sets
16.9 Result Set Metadata
16.10 Relational Data
Joining Data from Multiple Tables
An Order Entry System
16.11 Advanced Topics
Transactions
Stored Procedures
16.12 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Customer Inserter
2. Customer Updater
3. Unpaid Order Sum
4. Population Database
5. Personnel Database Creator
6. Employee Inserter
7. Employee Updater
8. PhoneBook Database
Chapter 17 A First Look at GUI Applications
Topics
17.1 Introduction
The JFC, AWT, and Swing
Event-Driven Programming
The javax.swing and java.awt Packages
17.2 Creating Windows
Using Inheritance to Extend the JFrame Class
Equipping GUI Classes with a main Method
Adding Components to a Window
Content Panes and Panels
Handling Events with Action Listeners
Writing Event Listener Classes as Private Inner Classes
Event Listeners Must Implement an Interface
Registering an Event Listener Object
Writing an Event Listener for the KiloConverter Class
Background and Foreground Colors
Changing the Background Color of a JFrame Object’s Content Pane
The ActionEvent Object
The getActionCommand Method
The getSource Method
Checkpoint
17.3 Layout Managers
Adding a Layout Manager to a Container
The FlowLayout Manager
Adjusting the FlowLayout Alignment
Adjusting the FlowLayout Component Gaps
The BorderLayout Manager
Nesting Panels Inside a Container’s Regions
The GridLayout Manager
Checkpoint
17.4 Radio Buttons and Check Boxes
Radio Buttons
Grouping with the ButtonGroup class
Responding to Radio Button Events
Determining in Code Whether a Radio Button Is Selected
Selecting a Radio Button in Code
Check Boxes
Responding to Check Box Events
Determining in Code Whether a Check Box Is Selected
Selecting a Check Box in Code
Checkpoint
17.5 Borders
17.6 Focus on Problem Solving: Extending Classes from JPanel
The Brandi’s Bagel House Application
The GreetingPanel Class
The BagelPanel Class
The ToppingPanel Class
The CoffeePanel Class
Putting It All Together
17.7 Splash Screens
17.8 Using Console Output to Debug a GUI Application
17.9 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Retail Price Calculator
2. Monthly Sales Tax
3. Property Tax
4. Travel Expenses
5. Theater Revenue
6. Joe’s Automotive
7. Long Distance Calls
8. Latin Translator
9. MPG Calculator
10. Celsius to Fahrenheit
Chapter 18 Advanced GUI Applications
Topics
18.1The Swing and AWT Class Hierarchy
18.2 Read-Only Text Fields
18.3 Lists
Selection Modes
Responding to List Events
Retrieving the Selected Item
Placing a Border around a List
Adding a Scroll Bar to a List
Adding Items to an Existing JList Component
Multiple Selection Lists
Single Interval Selection Mode
Multiple Interval Selection Mode
18.4 Combo Boxes
Retrieving the Selected Item
Editable Combo Boxes
Checkpoint
18.5 Displaying Images in Labels and Buttons
Checkpoint
18.6 Mnemonics and Tool Tips
Mnemonics
Tool Tips
Checkpoint
18.7 File Choosers and Color Choosers
File Choosers
Displaying a File Chooser Dialog Box
Color Choosers
18.8 Menus
Checkpoint
18.9 More about Text Components: Text Areas and Fonts
Text Areas
Fonts
Checkpoint
18.10 Sliders
Checkpoint
18.11 Look and Feel
18.12 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Scrollable Tax Calculator
2. Image Viewer
3. Dorm and Meal Plan Calculator
4. Skateboard Designer
5. Shopping Cart System
6. Cell Phone Packages
7. Shade Designer
8. Conference Registration System
9. Dice Simulator
10. Card Dealer
11. Tic Tac Toe Simulator
Chapter 19 Applets and More
Topics
19.1 Introduction to Applets
Checkpoint
19.2 A Brief Introduction to HTML
Hypertext
Markup Language
Document Structure Tags
Text Formatting Tags
Creating Breaks in Text
Inserting Links
Checkpoint
19.3 Creating Applets with Swing
Running an Applet
Running an Applet with appletviewer
Handling Events in an Applet
Checkpoint
19.4 Using AWT for Portability
Checkpoint
19.5 Drawing Shapes
The XY Coordinate System
Graphics Objects
The repaint Method
Drawing on Panels
Checkpoint
19.6 Handling Mouse Events
Handling Mouse Events
Using Adapter Classes
Checkpoint
19.7 Timer Objects
Checkpoint
19.8 Playing Audio
Using an AudioClip Object
Playing Audio in an Application
Checkpoint
19.9 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. FollowMe Applet
2. House Applet
3. WatchMe Applet
4. Thermometer Applet
5. Polygon Drawer
6. GridFiller Applet
7. DrinkMachine Applet
8. Stopwatch Applet
9. Slideshow Application
Chapter 20 Creating GUI Applications with JavaFX and Scene Builder
Topics
20.1 Introduction
Event-Driven Programming
Checkpoint
20.2 Scene Graphs
Checkpoint
20.3 Using Scene Builder to Create JavaFX Applications
Starting Scene Builder
The Scene Builder Main Window
Checkpoint
20.4 Writing the Application Code
The Main Application Class
The Controller Class
Using the Sample Controller Skeleton
Summary of Creating a JavaFX Application
Checkpoint
20.5 RadioButtons and CheckBoxes
RadioButtons
Determining in Code Whether a RadioButton Is Selected
Responding to RadioButton Events
CheckBoxes
Determining in Code Whether a CheckBox Is Selected
Responding to CheckBox Events
Checkpoint
20.6 Displaying Images
Displaying an Image with Code
Checkpoint
20.7 Common Errors to Avoid
Review Questions and Exercises
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Programming Challenges
1. Retail Price Calculator
2. Latin Translator
3. Name Formatter
4. Tip, Tax, and Total
5. Distance Traveled
6. Heads or Tails
7. Celsius and Fahrenheit Temperature Converter
8. Dice Simulator
9. Rock, Paper, Scissors Game
10. Tic-Tac-Toe Simulator
11. Slot Machine Simulation
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
Z
Appendix A The ASCII/Unicode Characters
Appendix B Operator Precedence and Associativity
Appendix C Java Key Words
Appendix D Installing the JDK and Using the JDK Documentation
Appendix E Using the javadoc Utility
Writing Documentation Comments
The @param Tag
The @return Tag
The @exception and @throws Tags
Running javadoc
The @author and @version Tags
Embedding HTML in Documentation Comments
The -public, -private, and -protected Command Line Options
Appendix F More about the Math Class
Appendix G Packages
Appendix H Working with Records and Random Access Files
Appendix I Configuring Java DB and Installing Apache Derby
Appendix J The QuickSort Algorithm
Appendix K Named Colors
Appendix L Answers to Checkpoints
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Online Chapter 17
Online Chapter 18
Online Chapter 19
Online Chapter 20
Appendix M Answers to Odd-Numbered Review Questions
Chapter 1
Multiple Choice
Find the Error
Algorithm Workbench
Predict the Result
Short Answer
Chapter 2
Multiple Choice and True/False
Predict the Output
Find the Error
Algorithm Workbench
Short Answer
Chapter 3
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 4
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 5
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 6
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 7
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 8
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 9
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 10
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 11
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 12
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 13
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 14
Multiple Choice and True/False
Algorithm Workbench
Short Answer
Chapter 15
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Chapter 16
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Online Chapter 17
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Online Chapter 18
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Online Chapter 19
Multiple Choice and True/False
Find the Error
Algorithm Workbench
Short Answer
Online Chapter 20
Multiple Choice and True / False
Find the Error
Algorithm Workbench
Short Answer
Case Study 1 Calculating Sales Commission
Program Design
Case Study 2 The Amortization Class
Calculations
Report Requirements
The Main Program
Case Study 3 The PinTester Class
Case Study 4 Parallel Arrays
Case Study 5 The FeetInches Class
More about the toString Method
The add Method
The equals Method
The copy Method
The Copy Constructor
Case Study 6 The SerialNumber Class
Case Study 7 A Simple Text Editor Application
File Menu
Font Menu