100% found this document useful (2 votes)
25 views82 pages

Java Programs To Accompany Programming Logic and Design 7th Edition Jo Ann Smith All Chapters Instant Download

Design

Uploaded by

drenitpatyco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
25 views82 pages

Java Programs To Accompany Programming Logic and Design 7th Edition Jo Ann Smith All Chapters Instant Download

Design

Uploaded by

drenitpatyco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Visit https://ebookultra.

com to download the full version and


explore more ebooks

Java Programs to Accompany Programming Logic and


Design 7th Edition Jo Ann Smith

_____ Click the link below to download _____


https://ebookultra.com/download/java-programs-to-
accompany-programming-logic-and-design-7th-edition-jo-
ann-smith/

Explore and download more ebooks at ebookultra.com


Here are some recommended products that might interest you.
You can download now and explore!

Microsoft Visual Basic Programs to Accompany Programming


Logic and Design 3rd Edition Jo Ann Smith

https://ebookultra.com/download/microsoft-visual-basic-programs-to-
accompany-programming-logic-and-design-3rd-edition-jo-ann-smith/

ebookultra.com

Java Programming 7th Edition Joyce Farrell

https://ebookultra.com/download/java-programming-7th-edition-joyce-
farrell/

ebookultra.com

Programming Logic and Design Comprehensive 6th Edition


Joyce Farrell

https://ebookultra.com/download/programming-logic-and-design-
comprehensive-6th-edition-joyce-farrell/

ebookultra.com

Java TM Programming From Problem Analysis to Program


Design 5th Edition D. S. Malik

https://ebookultra.com/download/java-tm-programming-from-problem-
analysis-to-program-design-5th-edition-d-s-malik/

ebookultra.com
Java the UML way integrating object oriented design and
programming Else Lervik

https://ebookultra.com/download/java-the-uml-way-integrating-object-
oriented-design-and-programming-else-lervik/

ebookultra.com

Laboratory Explorations to Accompany Microelectronic


Circuits 7th Edition Vincent C. Gaudet

https://ebookultra.com/download/laboratory-explorations-to-accompany-
microelectronic-circuits-7th-edition-vincent-c-gaudet/

ebookultra.com

Building Java Programs A Back to Basics Approach 3rd


Edition Stuart Reges

https://ebookultra.com/download/building-java-programs-a-back-to-
basics-approach-3rd-edition-stuart-reges/

ebookultra.com

Student Solutions Manual to accompany Complex Variables


and Applications 7th Edition James Ward Brown

https://ebookultra.com/download/student-solutions-manual-to-accompany-
complex-variables-and-applications-7th-edition-james-ward-brown/

ebookultra.com

Introduction to Programming with Java 3rd Edition John


Dean

https://ebookultra.com/download/introduction-to-programming-with-
java-3rd-edition-john-dean/

ebookultra.com
Java Programs to Accompany Programming Logic and
Design 7th Edition Jo Ann Smith Digital Instant
Download
Author(s): Jo Ann Smith
ISBN(s): 9781133526063, 1133526063
Edition: 7
File Details: PDF, 4.14 MB
Year: 2012
Language: english
SEVENTH EDITION

JAVA™ PROGRAMS
TO ACCOMPANY
PROGRAMMING LOGIC
AND DESIGN

BY JO ANN SMITH

Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions, some third party content may be suppressed. Editorial
review has deemed that any suppressed content does not materially affect the overall learning experience. The publisher reserves the right to
remove content from this title at any time if subsequent rights restrictions require it. For valuable information on pricing, previous
editions, changes to current editions, and alternate formats, please visit www.cengage.com/highered to search by
ISBN#, author, title, or keyword for materials in your areas of interest

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Java Programs to Accompany Programming © 2013 Course Technology, Cengage Learning
Logic and Design, Seventh Edition
ALL RIGHTS RESERVED. No part of this work covered by the copyright
Jo Ann Smith
herein may be reproduced, transmitted, stored, or used in any form or by
Executive Editor: Marie Lee any means graphic, electronic, or mechanical, including but not limited to
photocopying, recording, scanning, digitizing, taping, Web distribution,
Acquisitions Editor: Brandi Shailer
information networks, or information storage and retrieval systems, except
Senior Product Manager: Alyssa Pratt as permitted under Section 107 or 108 of the 1976 United States Copyright
Senior Content Project Manager: Act, without the prior written permission of the publisher.
Cathie DiMassa
Art Director: Faith Brosnan For product information and technology assistance, contact us at
Cengage Learning Customer & Sales Support, cengage.com/support
Compositor: Integra Software Services
For permission to use material from this text or product,
Cover Designer: Lisa Kuhn/Curio Press, LLC submit all requests online at www.cengage.com/permissions
HYPERLINK “http://www.curiopress.com/” Further permissions questions can be e-mailed to
www.curiopress.com [email protected]
Image credit: © Leigh Prather/Veer
Library of Congress Control Number: 2012931579
ISBN-13: 978-1-133-52606-3
ISBN-10: 1-133-52606-3
Course Technology
20 Channel Center Street
Boston, MA 02210
USA
Cengage Learning is a leading provider of customized learning solutions
with office locations around the globe, including Singapore, the United
Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at:
international.cengage.com/region
Cengage Learning products are represented in Canada by
Nelson Education, Ltd.
For your lifelong learning solutions, visit course.cengage.com
Visit our corporate Web site at cengage.com.
Some of the product names and company names used in this book have
been used for identification purposes only and may be trademarks or
registered trademarks of their respective manufacturers and sellers.
Any fictional data related to persons or companies or URLs used
throughout this book is intended for instructional purposes only. At the
time this book was printed, any such data was fictional and not belonging
to any real persons or companies.
Course Technology, a part of Cengage Learning, reserves the right to revise
this publication and make changes from time to time in its content without
notice.
The programs in this book are for instructional purposes only.
They have been tested with care, but are not guaranteed for any particular
intent beyond educational purposes. The author and the publisher do not
offer any warranties or representations, nor do they accept any liabilities
with respect to the programs.

Printed in the United States of America


1 2 3 4 5 6 7 16 15 14 13 12

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Brief Contents
iii

Pref ace . . . . . . . . . . . . . . . . . ix
CHAPTER 1 An In t ro ducti on to Jav a and the
J ava Pro grammi ng Env i ronment . . . . . . . 1
CHAPTER 2 Var iables, Constants, Operators,
an d Wr it i ng Programs Usi ng Sequenti al
St at em ents . . . . . . . . . . . . . . . . 13
CHAPTER 3 Wr it in g Structured Jav a Programs . . . . . . 33
CHAPTER 4 Wr it in g Programs that Make Deci si ons . . . . 48
CHAPTER 5 Wr it in g Programs Usi ng Loops . . . . . . . 75
CHAPTER 6 U s in g Ar ray s i n Jav a Programs . . . . . . 101
CHAPTER 7 F ile Han dl i ng and Appl i cati ons . . . . . . 118
CHAPTER 8 Advan ced Array Techni ques . . . . . . . . 135
CHAPTER 9 Advan ced Modul ari zati on Techni ques . . . . 152
CHAPTER 10 Addit io n al Topi cs . . . . . . . . . . . . 180
In dex . . . . . . . . . . . . . . . . . 197

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Contents
iv

Pref ace . . . . . . . . . . . . . . . . . ix

CHAPTER 1 An In t ro du c ti on to Jav a and the


J ava Pro g r a mmi ng Env i ronment . . . . . . . 1
The Java Programming Language . . . . . . . . . . . . . . 2
Three Types of Java Programs . . . . . . . . . . . . . . . 2
An Introduction to Object-Oriented Terminology . . . . . . . . 3
Downloading the Java Standard Edition
Development Kit (JDK) . . . . . . . . . . . . . . . . . . 5
The Structure of a Java Program . . . . . . . . . . . . . . 5
The Java Development Cycle . . . . . . . . . . . . . . . . 7
Writing Java Source Code. . . . . . . . . . . . . . . . . 8
Compiling a Java Program . . . . . . . . . . . . . . . . 8
Executing a Java Program . . . . . . . . . . . . . . . . 10
Exercise 1-1: Understanding Java Utilities . . . . . . . . . 11
Lab 1.1: Understanding Java Utilities . . . . . . . . . . . 12

CHAPTER 2 Var iables , Constants, Operators, and Wri ti ng


Pro g r am s Usi ng Sequenti al Statements . . . . 13
Variables . . . . . . . . . . . . . . . . . . . . . . . . . 14
Variable Names . . . . . . . . . . . . . . . . . . . . . 14
Java Data Types . . . . . . . . . . . . . . . . . . . . . 15
Exercise 2-1: Using Java Variables, Data Types,
and Keywords . . . . . . . . . . . . . . . . . . . . . 16
Declaring and Initializing Variables. . . . . . . . . . . . . . 16
Exercise 2-2: Declaring and Initializing Java Variables . . . . 17
Lab 2.1: Declaring and Initializing Java Variables . . . . . . 18
Constants . . . . . . . . . . . . . . . . . . . . . . . . . 19
Unnamed Constants . . . . . . . . . . . . . . . . . . . 19
Named Constants . . . . . . . . . . . . . . . . . . . . 19
Exercise 2-3: Declaring and Initializing Java Constants . . . 19
Lab 2.2: Declaring and Initializing Java Constants . . . . . . 20

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Arithmetic and Assignment Operators . . . . . . . . . . . . 20


Arithmetic Operators . . . . . . . . . . . . . . . . . . . 21
Assignment Operators and the Assignment Statement . . . . 22
Precedence and Associativity . . . . . . . . . . . . . . . 23
Exercise 2-4: Understanding Operator Precedence
and Associativity . . . . . . . . . . . . . . . . . . . . 24 v
Lab 2.3: Arithmetic and Assignment Operators . . . . . . . 25
Sequential Statements, Comments, and Interactive
Input Statements . . . . . . . . . . . . . . . . . . . . . 26
Exercise 2-5: Understanding Sequential Statements . . . . . 30
Lab 2.4: Understanding Sequential Statements . . . . . . . 31

CHAPTER 3 Wr it in g Structured Jav a Programs . . . . . . 33


Using Flowcharts and Pseudocode to Write a Java Program. . .34
Lab 3.1: Using Flowcharts and Pseudocode to
Write a Java Program . . . . . . . . . . . . . . . . . . 38
Writing a Modular Program in Java . . . . . . . . . . . . . 40
Lab 3.2: Writing a Modular Program in Java . . . . . . . . 47

CHAPTER 4 Wr it in g Programs that Make Deci si ons . . . . 48


Boolean Operators . . . . . . . . . . . . . . . . . . . . . 49
Relational Operators . . . . . . . . . . . . . . . . . . . 49
Logical Operators . . . . . . . . . . . . . . . . . . . . 50
Relational and Logical Operator Precedence
and Associativity . . . . . . . . . . . . . . . . . . . . 51
Comparing Strings . . . . . . . . . . . . . . . . . . . . . 53
Decision Statements . . . . . . . . . . . . . . . . . . . . 55
The if Statement . . . . . . . . . . . . . . . . . . . . 55
Exercise 4-1: Understanding if Statements . . . . . . . . 57
Lab 4.1: Understanding if Statements . . . . . . . . . . 58
The if-else Statement . . . . . . . . . . . . . . . . . 59
Exercise 4-2: Understanding if-else Statements . . . . . 61
Lab 4.2: Understanding if-else Statements . . . . . . . 62
Nested if Statements . . . . . . . . . . . . . . . . . . 63
Exercise 4-3: Understanding Nested if Statements . . . . . 65
Lab 4.3: Understanding Nested if Statements . . . . . . . 66
The switch Statement . . . . . . . . . . . . . . . . . 67
Exercise 4-4: Using a switch Statement . . . . . . . . . 68
Lab 4.4: Using a switch Statement . . . . . . . . . . . 69
Using Decision Statements to Make Multiple Comparisons . . . 70
Using AND Logic . . . . . . . . . . . . . . . . . . . . . 70
Using OR Logic . . . . . . . . . . . . . . . . . . . . . 71

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Exercise 4-5: Making Multiple Comparisons in Decision


Statements . . . . . . . . . . . . . . . . . . . . . . 72
Lab 4.5: Making Multiple Comparisons in
Decision Statements . . . . . . . . . . . . . . . . . . 73

vi CHAPTER 5 Wr it in g Programs Usi ng Loops . . . . . . . 75


The Increment (++) and Decrement (− −) Operators . . . . . 76
Exercise 5-1: Using the Increment (++)
and Decrement (−−) Operators . . . . . . . . . . . . . 77
Writing a while Loop in Java. . . . . . . . . . . . . . . . 78
Exercise 5-2: Using a while Loop . . . . . . . . . . . . 80
Using a Counter to Control a Loop . . . . . . . . . . . . . 80
Exercise 5-3: Using a Counter-Controlled while Loop . . . 81
Lab 5.1: Using a Counter-Controlled while Loop . . . . . . 82
Using a Sentinel Value to Control a Loop . . . . . . . . . . . 83
Exercise 5-4: Using a Sentinel Value to Control
a while Loop . . . . . . . . . . . . . . . . . . . . . 85
Lab 5.2: Using a Sentinel Value to Control a while Loop . . 86
Writing a for Loop in Java . . . . . . . . . . . . . . . . . 86
Exercise 5-5: Using a for Loop . . . . . . . . . . . . . . 88
Lab 5.3: Using a for Loop . . . . . . . . . . . . . . . . 89
Writing a do while Loop in Java . . . . . . . . . . . . . . 89
Exercise 5-6: Using a do while Loop . . . . . . . . . . . 90
Lab 5.4: Using a do while Loop . . . . . . . . . . . . . 91
Nesting Loops . . . . . . . . . . . . . . . . . . . . . . . 91
Exercise 5-7: Nesting Loops . . . . . . . . . . . . . . . 92
Lab 5.5: Nesting Loops . . . . . . . . . . . . . . . . . 93
Accumulating Totals in a Loop . . . . . . . . . . . . . . . 94
Exercise 5-8: Accumulating Totals in a Loop . . . . . . . . 96
Lab 5.6: Accumulating Totals in a Loop . . . . . . . . . . 97
Using a Loop to Validate Input . . . . . . . . . . . . . . . 98
Exercise 5-9: Validating User Input . . . . . . . . . . . . 99
Lab 5.7: Validating User Input . . . . . . . . . . . . . . 100

CHAPTER 6 U s in g Ar r ay s i n Jav a Programs . . . . . . 101


Array Basics . . . . . . . . . . . . . . . . . . . . . . 102
Declaring Arrays . . . . . . . . . . . . . . . . . . . . 102
Initializing Arrays . . . . . . . . . . . . . . . . . . . 104
Accessing Array Elements . . . . . . . . . . . . . . . 104
Staying Within the Bounds of an Array . . . . . . . . . . 105
Using Constants with Arrays . . . . . . . . . . . . . . 106
Exercise 6-1: Array Basics . . . . . . . . . . . . . . . 107
Lab 6.1: Array Basics . . . . . . . . . . . . . . . . . 107

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Searching an Array for an Exact Match . . . . . . . . . . 108


Exercise 6-2: Searching an Array for an Exact Match . . . 110
Lab 6.2: Searching an Array for an Exact Match . . . . . 111
Parallel Arrays. . . . . . . . . . . . . . . . . . . . . . 112
Exercise 6-3: Parallel Arrays . . . . . . . . . . . . . . 115
Lab 6.3: Parallel Arrays . . . . . . . . . . . . . . . . 116 vii

CHAPTER 7 F ile Han dl i ng and Appl i cati ons . . . . . . 118


File Handling . . . . . . . . . . . . . . . . . . . . . . 119
Importing Packages and Classes . . . . . . . . . . . . 119
Opening a File for Reading . . . . . . . . . . . . . . . 120
Reading Data from an Input File . . . . . . . . . . . . . 121
Reading Data Using a Loop and EOF . . . . . . . . . . . 122
Opening a File for Writing . . . . . . . . . . . . . . . . 122
Writing Data to an Output File . . . . . . . . . . . . . . 123
Exercise 7-1: Opening Files and Performing File Input . . . 125
Lab 7.1: Opening Files and Performing File Input . . . . . 126
Understanding Sequential Files and Control Break Logic . . . 126
Exercise 7-2: Accumulating Totals in Single-Level
Control Break Programs . . . . . . . . . . . . . . . 132
Lab 7.2: Accumulating Totals in Single-Level
Control Break Programs . . . . . . . . . . . . . . . 132

CHAPTER 8 Advan ced Array Techni ques . . . . . . . . 135


Sorting Data . . . . . . . . . . . . . . . . . . . . . . 136
Swapping Data Values . . . . . . . . . . . . . . . . . . 137
Exercise 8-1: Swapping Values . . . . . . . . . . . . . 137
Lab 8.1: Swapping Values . . . . . . . . . . . . . . . 138
Using a Bubble Sort . . . . . . . . . . . . . . . . . . . 138
The main () Method . . . . . . . . . . . . . . . . . 142
The fillArray() Method. . . . . . . . . . . . . . . 143
The sortArray() Method. . . . . . . . . . . . . . . 144
The displayArray() Method . . . . . . . . . . . . . 145
Exercise 8-2: Using a Bubble Sort . . . . . . . . . . . . 145
Lab 8.2: Using a Bubble Sort . . . . . . . . . . . . . . 146
Using Multidimensional Arrays . . . . . . . . . . . . . . 147
Exercise 8-3: Using Multidimensional Arrays . . . . . . . 150
Lab 8.3: Using Multidimensional Arrays . . . . . . . . . 150

CHAPTER 9 Advan ced Modul ari zati on Techni ques . . . . 152


Writing Methods with No Parameters . . . . . . . . . . . 153
Exercise 9-1: Writing Methods with No Parameters . . . . 155
Lab 9.1: Writing Methods with No Parameters . . . . . . 156

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS

Writing Methods that Require a Single Parameter . . . . . . 156


Exercise 9-2: Writing Methods that Require
a Single Parameter . . . . . . . . . . . . . . . . . . 159
Lab 9.2: Writing Methods that Require a Single
Parameter . . . . . . . . . . . . . . . . . . . . . . 160
viii
Writing Methods that Require Multiple Parameters . . . . . 160
Exercise 9-3: Writing Methods that Require
Multiple Parameters . . . . . . . . . . . . . . . . . . 162
Lab 9.3: Writing Methods that Require Multiple
Parameters . . . . . . . . . . . . . . . . . . . . . 163
Writing Methods that Return a Value . . . . . . . . . . . . 164
Exercise 9-4: Writing Methods that Return a Value . . . . 166
Lab 9.4: Writing Methods that Return a Value . . . . . . . 167
Passing an Array and an Array Element to a Method . . . . 168
Exercise 9-5: Passing Arrays to Methods . . . . . . . . . 171
Lab 9.5: Passing Arrays to Methods . . . . . . . . . . . 172
Overloading Methods. . . . . . . . . . . . . . . . . . . 172
Exercise 9-6: Overloading Methods . . . . . . . . . . . . 175
Lab 9.6: Overloading Methods . . . . . . . . . . . . . 176
Using Java’s Built-In Methods . . . . . . . . . . . . . . . 177
Exercise 9-7: Using Java’s Built-In Methods . . . . . . . . 177
Lab 9.7: Using Java’s Built-In Methods . . . . . . . . . . 178

CHAPTER 10 Addit io n al Topi cs . . . . . . . . . . . . 180


A Programmer-Defined Class . . . . . . . . . . . . . . . 181
Creating a Programmer-Defined Class . . . . . . . . . . 182
Adding Attributes to a Class . . . . . . . . . . . . . . 184
Adding Methods to a Class . . . . . . . . . . . . . . . 184
Exercise 10-1: Creating a Programmer-Defined
Class in Java. . . . . . . . . . . . . . . . . . . . . 187
Lab 10.1: Creating a Programmer-Defined Class in Java . . 189
Creating a Graphical User Interface (GUI) . . . . . . . . . 190
Writing a Constructor . . . . . . . . . . . . . . . . . 192
Writing the main() Method . . . . . . . . . . . . . . 194
Exercise 10-2: Creating a Graphical User Interface
in Java . . . . . . . . . . . . . . . . . . . . . . . 195
Lab 10.2: Creating a Graphical User Interface in Java . . . 196

In dex . . . . . . . . . . . . . . . . . 197

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface
ix

Java Programs to Accompany Programming Logic and Design,


Seventh Edition (also known as Java PAL) is designed to provide
students with an opportunity to write Java programs as part of
an introductory programming logic course. It accompanies the
student’s primary text, Programming Logic and Design, Seventh
Edition, by Joyce Farrell. This textbook assumes no programming
language experience and provides the beginning programmer
with a guide to writing structured programs and simple object-
oriented programs using introductory elements of the popular Java
programming language. It is not intended as a textbook for a course
in Java programming. The writing is nontechnical and emphasizes
good programming practices. The examples do not assume
mathematical background beyond high school math. Additionally,
the examples illustrate one or two major points; they do not contain
so many features that students become lost following irrelevant and
extraneous details.
The examples in Java PAL, Seventh Edition are often examples pre-
sented in the primary textbook, Programming Logic and Design,
Seventh Edition. The following table shows the correlation between
topics in the two books.

Programming Logic
Java PAL, Seventh Edition and Design, Seventh Edition
Chapter 1: An Introduction to Chapter 1: An Overview of
Java and the Java Programming Computers and Logic
Environment
Chapter 2: Variables, Constants, Chapter 2: Working with Data,
Operators, and Writing Programs Creating Modules, and Designing
Using Sequential Statements High-Quality Programs
Chapter 3: Understanding Structure
Chapter 3: Writing Structured Java Chapter 2: Working with Data,
Programs Creating Modules, and Designing
High-Quality Programs
Chapter 3: Understanding Structure
(continues)

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
P R E FA C E

(continued)

Programming Logic
Java PAL, Seventh Edition and Design, Seventh Edition
Chapter 4: Writing Programs That Chapter 4: Making Decisions
Make Decisions
x Chapter 5: Writing Programs Using Chapter 5: Looping
Loops
Chapter 6: Using Arrays in Java Chapter 6: Arrays
Programs
Chapter 7: File Handling and Chapter 7: File Handling and
Applications Applications
Chapter 8: Advanced Array Chapter 8: Advanced Array Concepts,
Techniques Indexed Files, and Linked Lists
Chapter 9: Advanced Modularization Chapter 9: Advanced Modularization
Techniques Techniques
Chapter 10: Additional Topics Chapter 10: Object-Oriented
Programming
Chapter 11: More Object-Oriented
Programming Concepts
Chapter 12: Event Driven GUI
Programming, Multithreading,
and Animation

Organization and Coverage


Java Programs to Accompany Programming Logic and Design, Seventh
Edition provides students with a review of the programming concepts
they are introduced to in their primary textbook. It also shows them
how to use Java to transform their program logic and design into
working programs. Chapter 1 introduces the structure of a Java
program, how to compile and run a Java program, and introductory
object-oriented concepts. Chapter 2 discusses Java’s data types,
variables, constants, arithmetic and assignment operators, and using
sequential statements to write a complete Java program. In Chapter
3, students learn how to transform pseudocode and flowcharts
into Java programs. Chapters 4 and 5 introduce students to writing
Java programs that make decisions and programs that use looping
constructs. Students learn to use Java to develop more sophisticated
programs that include using arrays, control breaks, and file input
and output in Chapters 6 and 7. In Chapter 8, students learn about
sorting data items in an array and using multidimensional arrays.
Passing parameters to procedures is introduced in Chapter 9. Lastly,

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
P R E FA C E

in Chapter 10, students use Java to write programs that include


programmer-defined classes. This last chapter also gives students
some experience in creating a graphical user interface (GUI).
This book combines text explanation of concepts and syntax along
with pseudocode and actual Java code examples to provide students
with the knowledge they need to implement their logic and program xi
designs using the Java programming language. This book is written
in a modular format and provides paper-and-pencil exercises as well
as lab exercises after each major topic is introduced. The exercises
provide students with experience in reading and writing Java code as
well as modifying and debugging existing code. In the labs, students
are asked to complete partially prewritten Java programs. Using
partially prewritten programs allows students to focus on individual
concepts rather than an entire program. The labs also allow students
to see their programs execute.
Java PAL, Seventh Edition is unique because:
• It is written and designed to correspond to the topics in the
primary textbook, Programming Language and Design, Seventh
Edition.
• The examples are everyday examples; no special knowledge of
mathematics, accounting, or other disciplines is assumed.
• It introduces students to introductory elements of the Java
programming language rather than overwhelming beginning
programmers with more detail than they are prepared to use
or understand.
• Text explanations are interspersed with pseudocode from the
primary book, thus reinforcing the importance of programming
logic.
• Complex programs are built through the use of complete
examples. Students see how an application is built from start
to finish instead of studying only segments of programs.

Features of the Text


Every chapter in this book includes the following features. These
features are both conducive to learning in the classroom and enable
students to learn the material at their own pace.
• Objectives: Each chapter begins with a list of objectives so the
student knows the topics that will be presented in the chapter.
In addition to providing a quick reference to topics covered, this
feature provides a useful study aid.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
P R E FA C E

• Figures and illustrations: This book has plenty of visuals, which


provide the reader with a more complete learning experience,
rather than one that involves simply studying text.
• Notes: These brief notes provide additional information—for
example, a common error to watch out for.
xii
• Exercises: Each section of each chapter includes meaningful
paper-and-pencil exercises that allow students to practice the skills
and concepts they are learning in the section.
• Labs: Each section of each chapter includes meaningful lab work
that allows students to write and execute programs that implement
their logic and program design.

Acknowledgments
I would like to thank all the people who helped to make this book
possible. Thanks to Alyssa Pratt, Senior Product Manager, and Brandi
Shailer, Acquisitions Editor, for their help and encouragement. I am
grateful to Cathie DiMassa, Senior Content Project Manager, Serge
Palladino, Quality Assurance, and Sreemannarayana Reddy Syakam,
of Integra Software Services, for overseeing the production of the
printed book. It is a pleasure to work with so many fine people who
are dedicated to producing quality instructional materials.
I am dedicating this book to my husband, Ray, our son, Tim, and our
grandson, William.
Jo Ann Smith

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Read This Before
You Begin xiii

To the User
Data Files
To complete most of the lab exercises, you will need data files that
have been created for this book. Your instructor can provide the data
files. You can also obtain the files electronically from the publisher at
www.CengageBrain.com (search under the ISBN for this book), and
then searching for this book title.
You can use a computer in your school lab or your own computer to
complete the lab exercises in this book.

Solutions
Solutions to the Exercises and Labs are provided to instructors on the
Course Technology Web site at login.cengage.com. The solutions are
password protected.

Using Your Own Computer


To use your own computer to complete the material in this book,
your computer must be included in the list of Java-supported
systems. To view this list, go to http://www.oracle.com/technetwork/
java/javase/config-417990.html.
This book was written using Microsoft Windows Vista and
Quality Assurance tested using Microsoft Windows 7.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
R E A D T HRI SE B
AEDF O
TRHEI SY OBUEBFEOGRI N
E

Downloading the Java Standard Edition


Development Kit (JDK7) for the Windows Platform
To download JDK7, go to the download Web site at
http://www.oracle.com/technetwork/java/javase/downloads/index
.html.
xiv
• Click the Download button under the JDK heading in the Java
Platform, Standard Edition, Java SE 7uX section of the web page. The
“X” represents a digit that changes as Sun releases new downloads. You
may have to scroll down to be able to see the Download button.
• On the next screen, find your operating system platform (e.g.,
Windows) from the list, select the radio button next to the words
Accept License Agreement, and then click the link on the same
line as your operating system.
• When the next window appears, you are asked if you want to save the
download file. Click Save File (Firefox) or Save (Internet Explorer).
• In the Save As dialog box (Internet Explorer) or the “Enter name
of file to save to . . . ” window (Firefox), specify your Desktop as
the location in which to save the downloaded file, then click Save.
(In Firefox, the file may automatically be downloaded to your
Downloads folder.) You will be downloading the file named jdk-
7ux-windows-i586.exe. The “x” represents a digit that change as
Sun releases new downloads. Depending on the speed of your
connection, this could take some time.
• When the download is complete, note that the size of the file
(in bytes) is provided on the download screen. Check that the
file you downloaded is the same size. This means you have
downloaded the full, uncorrupt file.

Installing the Java Standard Edition


Development Kit (JDK7)
• On your Desktop, double-click jdk-7uX-windows-i586.exe. This
starts the installation program.
• Next,
• In Vista: You may have to click the Continue button on the
User Account Control dialog box.
• In XP: Click Run on the Open File Security Warning dialog box.
• In Windows 7: You may have to click the Yes button in the User
Account Control dialog box.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
RR
EAED
ATDH T
I SHBI E
SF O
BREE
FOYO
R UE B E G I N

• In the Setup Dialog Box, click the Next button.


• In the Custom Setup dialog box, select Development Tools if it
is not already selected. At the bottom left, you see “Install to.” By
default, the files will be installed in the C:\Program Files\Java\
jdk1.7.0_XX\ folder. You should not change this location unless
you have a good reason to do so. xv

• Click the Next button.


• After a few moments, the Destination Folder dialog box is
displayed, showing you the folder where Java will be installed. You
should not change this location unless you have a good reason to
do so. Click the Next button.
• The Java Setup program now installs the Java SE Development
Kit 7. Files are copied to the appropriate folders. This takes a few
minutes. When the setup is complete, you see the message “Java SE
Development Kit 7 Update XX Successfully Installed” in the dialog
box. Click Finish to complete the setup.
• When the installation is complete, you can delete the downloaded
file, jdk-7uxx-windows-i586.exe to recover disk space.

Updating Your PATH Environment Variable


Setting the PATH variable allows you to use the compiler (javac) and
bytecode interpreter (java) without having to specify the full path for
the command.
To set the PATH permanently in Windows 7:
1. Clic k the Start button in the lower left corner of your
Desktop.
2. S elect Control Panel, click System and Security, and then
click System.
3. S elect the Advanced system settings link. Click Yes.
4. In the System Properties dialog box, select the Advanced
tab, if necessary, and then click the Environment Variables
button.
5. S elect PATH or Path in the User variables or System
variables section, click Edit, and then edit the PATH variable
by adding the following to the end of the current PATH:
;C:\Program Files\Java\jdk1.7.0_XX\bin

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
R E A D T HRI SE B
AEDF O
TRHEI SY OBUEBFEOGRI N
E

Note that it is important to include the semicolon (;) at the


beginning of the path, preceding C:\. Replace the “XX” with
the update number you have downloaded. A typical PATH
might look like this:
C:\Windows;C:\Windows\System32;C:\Program Files\Java\
xvi jdk1.7.0_01\bin
6. When you are finished editing the PATH variable, click OK.
7. Clic k OK on the Environment Variables dialog box.
8. Clic k OK on the System Properties dialog box.
9. Close the System window.
To set the PATH permanently in Windows Vista:
1. Clic k the Start button in the lower left corner of your
Desktop.
2. S elect Control Panel and then select Classic View,
if necessary.
3. D ouble-click System.
4. S elect the Advanced system settings link. Click Continue,
if necessary.
5. In the System Properties dialog box, select the Advanced tab, if
necessary, and then click the Environment Variables button.
6. S elect PATH or Path in the User variables or System
variables section, click Edit, and then edit the PATH variable
by adding the following to the end of the current PATH:
;C:\Program Files\Java\jdk1.7.0_XX\bin
Note that it is important to include the semicolon (;) at the
beginning of the path, preceding C:\. Replace the “XX” with
the update number you have downloaded. Add the path to the
end of the current PATH. A typical PATH might look like this:
C:\Windows;C:\Windows\System32;C:\Program Files\Java\
jdk1.7.0_01\bin
7. When you are finished editing the PATH variable, click OK.
8. Clic k OK on the Environment Variables dialog box.
9. Clic k OK on the System Properties dialog box.
10. Close the System window.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
RR
EAED
ATDH T
I SHBI E
SF O
BREE
FOYO
R UE B E G I N

To set the PATH permanently in Windows XP:


1. Clic k the Start button in the lower left corner of your
Desktop.
2. S elect Control Panel and then double-click System.
3. In the System Properties dialog box, select the Advanced tab, xvii
and then click the Environment Variables button.
4. S elect PATH or Path in the User variables or System
variables section, click Edit, and then edit the PATH variable
by adding the following to the end of the current PATH:
;C:\Program Files\Java\jdk1.7.0_XX\bin
Note that it is important to include the semicolon (;) at the
beginning of the path, preceding C:\. Replace the “XX” with
the update number you have downloaded. A typical PATH
might look like this:
C:\Windows;C:\Windows\System32;C:\Program Files\Java\
jdk1.7.0_01\bin
5. When you are finished editing the PATH variable, click OK.
6. Clic k OK on the Environment Variables dialog box.
7. Clic k OK on the System Properties dialog box.
8. Close the System window.
Capitalization does not matter when you are setting the PATH
variable. The PATH is a series of folders separated by semicolons (;).
Windows searches for programs in the PATH folders in order, from
left to right.
To fi nd out the current value of your PATH, at the prompt in a
Command Prompt window, type: path.

Updating Your CLASSPATH Environment Variable


Setting the CLASSPATH variable allows you to execute Java
programs without having to specify the full path for the program.
You may not have to update the CLASSPATH environment variable
unless instructed to do so by your professor.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
R E A D T HRI SE B
AEDF O
TRHEI SY OBUEBFEOGRI N
E

If you do want to update the CLASSPATH environment variable,


follow the steps you used to edit the PATH variable up to the point
of editing the PATH variable. Then do the following:
1. S elect CLASSPATH or classpath in the User variables
or System variables section, click Edit, and then edit the
xviii CLASSPATH variable by adding a semicolon (;) followed
by a period (.) to the end of the “CLASSPATH”. A typical
CLASSPATH might look like this:
C:\Program Files\Java\jdk1.7.0_01\bin;.
2. When you are finished editing the CLASSPATH variable,
click OK.
3. Clic k OK on the Environment Variables dialog box.
4. Clic k OK on the System Properties dialog box.
5. Close the System window.
If you don’t have a CLASSPATH environment variable, click the New
button, enter CLASSPATH for the variable name and a period (.) for
the variable value.
Capitalization does not matter when you are setting the CLASSPATH
variable. The CLASSPATH is a series of folders separated by
semicolons (;). Java searches for classes in the CLASSPATH folders in
order, from left to right.
To fi nd out the current value of your CLASSPATH, at the prompt in a
Command Prompt window, type: set classpath.

To the Instructor
To complete some of the Exercises and Labs in this book, your
students must use the data files provided with this book. These files
are available from the publisher at www.CengageBrain.com (search
under the ISBN for this book). Follow the instructions in the Help file
to copy the data files to your server or stand-alone computer. You can
view the Help file using a text editor such as WordPad or Notepad.
Once the files are copied, you may instruct your students to copy the
files to their own computers or workstations.

Course Technology Data Files


You are granted a license to copy the data files to any computer or
computer network used by individuals who have purchased this book.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
An Introduction
CHAPTER 1
to Java and the
Java Programming
Environment

After studying this chapter, you will be able to:

 Discuss the Java programming language and its history


 Recognize the three types of Java programs
 Explain introductory concepts and terminology used in
object-oriented programming
 Download the Java Standard Edition Development Kit (JDK)
 Recognize the structure of a Java program
 Complete the Java development cycle, which includes
creating a source code file, compiling the source code,
and executing a Java program

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 An Introduction to Java and the Java Programming Environment

You should do the exercises and labs in this chapter only after you
have finished Chapter 1 of your book, Programming Logic and Design,
Seventh Edition, by Joyce Farrell. This chapter introduces the Java
programming language and its history. It explains some introductory
object-oriented concepts, describes the process of compiling and
executing a Java program, and explains how to download the Java
2
Standard Edition Development Kit (JDK). You begin writing Java pro-
grams in Chapter 2 of this book.

The Java Programming Language


The Java programming language was developed by Dr. James Gosling
and introduced by Sun Microsystems in late 1995. It became very
popular in a short period of time, mostly due to the rising popularity of
the World Wide Web. Java is a programming language that can be used
to create interactive Web pages and to write Web-based applications
that run on Web servers. Web servers are the computers that “serve
up” content when you request to view Web pages. An online bookstore
and an online course registration system are examples of Web-based
applications. Java is also used to develop stand-alone enterprise
applications (programs that help manage data and run a business) and
applications for cell phones, cable boxes, e-readers, and parking meters.
What makes Java especially useful is that it is an object-oriented
programming language. The term object-oriented encompasses a
number of concepts explained later in this chapter and throughout
this book. For now, all you need to know is that an object-
oriented programming language is modular in nature, allowing the
Many of the programmer to build a program from reusable parts of programs
terms used to called classes, objects, and methods.
describe the
JDK may be The Java programming language is just one part of an object-oriented
unfamiliar to system called the Java Standard Edition Development Kit (JDK). You
you. Don’t worry about will use the JDK when you write, compile, and execute Java programs
that right now. By the in this book. The JDK includes many reusable parts of programs,
time you finish with this
called packages. Programmers use these packages to simplify their
chapter, you will under-
stand this new terminol-
programming tasks. The JDK also includes development tools used
ogy and you will even be by program developers. Examples of development tools include the
using some of the tools compiler (javac) and the bytecode interpreter (java) that you will
that are part of the JDK. use later in this chapter.

Three Types of Java Programs


Java programs can be written as applications, servlets, or applets.
An application is a stand-alone program. A servlet is a Java pro-
gram that runs on a Web server or application server and provides
server-side processing, such as accessing a database and handling

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
An Introduction to Object-Oriented Terminology

e-commerce transactions. An applet is a Java program that is exe-


cuted and viewed in a browser such as Mozilla Firefox or Internet
Explorer. In this book, you will write applications, which means you
will be writing stand-alone Java programs.

An Introduction to Object-Oriented 3

Terminology
You must understand a few object-oriented concepts to be successful
at reading and working with Java programs in this book. Note, how-
ever, that you will not learn enough to make you a Java programmer.
You will have to take additional courses in Java to become a Java pro-
grammer. This book teaches you only the basics.
To fully understand the term object-oriented, you need to know a
little about procedural programming. Procedural programming is
a style of programming that is older than object-oriented program-
ming. Procedural programs consist of statements that the computer
runs or executes. Many of the statements make calls (a request to
run or execute) to groups of other statements that are known as
procedures, modules, methods, or subroutines. These programs are
known as “procedural” because they perform a sequence of proce-
dures. Procedural programming focuses on writing code that takes
some data (for example, some sales figures), performs a specific task
using the data (for example, adding up the sales figures), and then
produces output (for example, a sales report). When people who use
procedural programs (the users) decide that they want their pro-
grams to do something slightly different, a programmer must revise
the program code, taking great care not to introduce errors into the
logic of the program.
Today, we need computer programs that are flexible and easy to
revise. Object-oriented programming languages, including Java, were
introduced to meet this need. In object-oriented programming, the
programmer can focus on the data that he or she wants to manipu-
late, rather than the individual lines of code required to manipulate
that data (although those individual lines still must be written even-
tually). An object-oriented program is made up of a collection of
interacting objects.
An object represents something in the real world, such as a car, an
employee, or an item in an inventory. An object includes (or encap-
sulates) both the data related to the object and the tasks you can
perform on that data. The term behavior is sometimes used to refer
to the tasks you can perform on an object’s data. For example, the
data for an inventory object might include a list of inventory items,

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 An Introduction to Java and the Java Programming Environment

the number of each item in stock, the number of days each item has
been in stock, and so on. The behaviors of the inventory object might
include calculations that add up the total number of items in stock
and calculations that determine the average amount of time each item
remains in inventory.
4 In object-oriented programming, the data items within an object are
known collectively as the object’s attributes. You can think of an
attribute as one of the characteristics of an object, such as its shape,
its color, or its name. The tasks the object performs on that data are
known as the object’s methods. (You can also think of a method as
an object’s behavior.) Because methods are built into objects, when
you create a Java program, you don’t always have to write multiple
lines of code telling the program exactly how to manipulate the
object’s data. Instead, you can write a shorter line of code, known as a
call, that passes a message to the method indicating that you need it
to do something.
For example, you can display dialog boxes, scroll bars, and buttons for
a user of your program to type in or click on simply by sending a mes-
sage to an existing object. At other times, you will be responsible for
creating your own classes and writing the code for the methods that
are part of that class. Whether you use existing, prewritten classes or
create your own classes, one of your main jobs as a Java programmer
is to communicate with the various objects in a program (and the
methods of those objects) by passing messages. Individual objects in a
program can also pass messages to other objects.
When Java programmers begin to write a program, they must begin
by creating a class. A class can be thought of as a template for a
group of similar objects. In a class, the programmer specifies the data
(attributes) and behaviors (methods) for all objects that belong to that
class. An object is sometimes referred to as an instance of a class,
and the process of creating an object is referred to as instantiation.
To understand the terms class, instance, and instantiation, it’s help-
ful to think of them in terms of a real-world example—baking a
chocolate cake. The recipe is similar to a class, and an actual cake is
an object. If you wanted to, you could create many chocolate cakes
that are all based on the same recipe. For example, your mother’s
birthday cake, your sister’s anniversary cake, and the cake for your
neighborhood bake sale all might be based on a single recipe that
contains the same data (ingredients) and methods (instructions). In
object-oriented programming, you can create as many objects as you
need in your program from the same class.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
The Structure of a Java Program

Downloading the Java Standard Edition


Development Kit (JDK)
All the examples in this book were created using the Java Standard
Edition Development Kit (JDK 7). You can get your own copy of the
JDK and install it on your computer at home, or your school may 5
have the JDK installed in your lab.
To get your own copy, go to the Java SE Web site at http://www
.oracle.com/technetwork/java/javase/downloads/index.html. Click the
Download button in the Java Platform (JDK) 7 section. Then follow
the directions for downloading and installing the correct version of
the software for your computer’s operating system. Refer to the “Read
This Before You Begin” section at the front of this book, or ask your
instructor, if you have questions regarding this process.

The Structure of a Java Program


When a programmer learns a new programming language, the first
program he or she traditionally writes is a Hello World program—a
program that displays the message “Hello World” on the screen.
Creating this simple program illustrates that the language is capable
of instructing the computer to communicate with the outside world.
The Java version of the Hello World program is shown in Figure 1-1.

public class HelloWorld


{
public static void main(String args[])
{
System.out.println("Hello World.");
}
}

Figure 1-1 Hello World program

At this point, you’re not expected to understand all the code in


Figure 1-1. Just notice that the code begins with the word public, fol-
lowed by the word class. Both public and class are special words,
known as keywords, which are reserved by Java to have a special
meaning. The keyword public indicates that the class you are about
to create should be available when the program executes. The class
keyword tells the Java compiler that you are beginning the creation
of a class and that what follows is part of that class. The name of the

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 An Introduction to Java and the Java Programming Environment

In Java, it is a class is up to you; however, the name should be meaningful, and it


convention to cannot contain any spaces. Because this program is written to display
begin class
the words “Hello World” on the user’s screen, it makes sense to name
names with a
capital letter.
the class HelloWorld.
If a class name is made The opening curly brace ( { ) on the second line of Figure 1-1 marks
up of two or more words,
6 the beginning of the class named HelloWorld. The closing curly brace
the first letter of each
( } ) on the last line of Figure 1-1 marks the end of the class.
word in the name is typi-
cally capitalized, with no Below the opening curly brace you see the method named main().
spaces between the
words. This is a special method in a Java program; the main() method is the
first method that executes when any program runs. The programs
You can tell in the first eight chapters of this book will include only the main()
main() is a method. In later chapters you will be able to include additional
method methods.
because of
the parenthe- The first part of any method is its header. In Figure 1-1, the header
ses; all Java method for the main() method begins with the public keyword, followed
names are followed by by the static keyword, followed by the void keyword, followed by
parentheses. the method name, which is main(). The public keyword makes this
method available to a user who wants to run the program. At this
point, you don’t have to understand the keyword static. Just keep in
mind that it’s necessary to make the Hello World program work.
To understand the keyword void you need to know that methods
often create some kind of output (for example, the result of a calcula-
tion), which can then be used elsewhere in the program. Another way
to say this is that methods sometimes return a value. In Figure 1-1,
the keyword void indicates that the main() method does not return
anything. You will learn more about methods returning values in
Chapter 9 of this book.
When we use the main() method in Java code, we always insert
String args[] within the parentheses following the word main, like
this: main(String args[]). This makes it possible to pass some argu-
ments, or values, to the main() method. You will learn more about
passing arguments to methods in Chapter 9. For now, you will have
to include String args[] in the parentheses without understanding
why. Remember that Java is a complex programming language; you
will have much more to learn about it after you finish this course in
order to become a Java programmer.
The line following the header for main() begins with another open-
ing curly brace. This curly brace marks the beginning of the main()
method. The closing curly brace on the second-to-last line of Figure 1-1
marks the end of the main() method. All the code within this pair of
curly braces executes when the main() method executes. In Figure 1-1,
there is only this one line of code between the curly braces:

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
The Java Development Cycle

System.out.println("Hello World.");

This is the line that causes the words “Hello World.” to appear on
the user’s screen. This line consists of two parts. The first part,
System.out.println();, prints (that is, displays on the screen) what-
ever is included within its parentheses. In this example, the parentheses
contain the message “Hello World.” so that is what will appear on the 7
screen. (The quotation marks will not appear on the screen, but they are
necessary to make the program work.) Note that the semicolon that ends
the System.out.println("Hello World."); statement is required
because it tells the compiler that this is the end of the statement.
In the statement System.out.println("Hello World.");, System
is a class, out is an object, and println() is a method. Java programs
frequently use this class-dot-object-dot-method syntax.
Next, you learn about the Java development cycle so that later in this
chapter, you can compile the Hello World program and execute it.
The Hello World program is saved in a file named HelloWorld.java
and is included in the student files for this chapter.

The Java Development Cycle


When you finish designing a program and writing the Java code that
implements your design, you must compile and execute your program.
This three-step process of writing code, compiling code, and executing
code is called the Java development cycle. It is illustrated in Figure 1-2.
Let’s begin by learning about Step 1, writing the Java source code.

Step 1 Step 2
Write Java Source code file Compile
source code (MyClass.java) source code
(Notepad) (javac MyClass.java)

Java bytecode
(MyClass.class)
Step 3
Execute the
program
(java MyClass)

Output

Figure 1-2 The Java development cycle

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 An Introduction to Java and the Java Programming Environment

Writing Java Source Code


As you learned in the previous section, you write a Java program
by creating a class and including a method named main() in the
class. But what do you use to write the program, and where do you
save it?
8
To write a Java program, you use a text editor, such as the Windows
text editor, Notepad. You can use any text editor, but the steps in this
book assume you are using Notepad. To start Notepad, click the Start
button, point to Programs or All Programs, click Accessories, and
then click Notepad. Once Notepad starts, you simply type in your
Java source code. Source code is the name used for the statements
that make up a Java program. For example, the code shown earlier in
Figure 1-1 is source code.
The name of When you save the file that contains the source code, it is impor-
the file and tant to name the file using the same name as the class and to
the name
add the extension .java. For the Hello World program, the class
of the class
must match
is named HelloWorld; therefore, the name of the source code
exactly, including upper- file must be HelloWorld.java. Of course, it is also important to
case and lowercase let- remember the location of the folder in which you choose to save
ters. It would not be your source code file.
correct to name the
source code file You move on to Step 2 of the Java development cycle after saving
helloworld.java your source code file. In Step 2, you compile the source code.
because the lowercase
“h” and lowercase “w” do
not match the uppercase Compiling a Java Program
“H” and uppercase “W” in
the class name. As you learned earlier in this chapter, the JDK contains several
utility programs. One of these utilities is the Java compiler, named
javac. The javac compiler is responsible for taking your source
code and transforming it into bytecode. Bytecode is intermediate,
machine-independent code. Intermediate means that the code is
between source code and machine code. Machine code is made
up of 1s and 0s, which a computer needs to execute a program. The
Java compiler automatically saves the intermediate bytecode in a
file. This file has the same name as the source code file, but it has a
.class extension rather than a .java extension. The bytecode gen-
erated by the compiler is platform independent. This is an impor-
tant feature of Java. Platform independence means that the same
Java program can be executed on many different types of computers
that run many different operating systems.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
The Java Development Cycle

The following steps show how to compile a source code file.


These steps assume you have already created and saved the The PATH
HelloWorld.java source code file. environment
variable tells
1. S et your PATH environment variable. Refer to “Read This your operating
Before You Begin” at the front of this book or ask your system which
instructor for instructions on how to set the PATH environ- directories on your sys- 9
ment variable. tem contain commands.

2. S et your CLASSPATH environment variable. Refer to the “Read The


This Before You Begin” section at the beginning of this book CLASSPATH
environment
for instructions on how to set the CLASSPATH environment
variable tells
variable.
your operating
3. Open a Command Prompt window. To do this in Windows system which directories
XP, Vista, or Windows 7, click the Start button, point to All on your system contain
resources it needs to run
Programs, click Accessories, and then click Command
your program.
Prompt. The cursor blinks to the right of the current file path.
4. To compile your source code file, you first have to change to
the file path containing your source code file. To do this, type If you are
cd driveletter:\path where driveletter is the drive contain- working in a
ing your file, and path is the path to the folder containing school com-
puter lab, the
your file. For example, to open a file stored in a folder named
first two steps
“Testing,” which is in turn stored in a folder named “My might already have been
Program,” which is stored on the C: drive, you would type cd performed for you.
C:\My Program\Testing. After you type the command, press
Enter. The cursor now blinks next to the file path for the
folder containing your source code file.
5. Type the following command, which uses the Java compiler,
javac, to compile the program:
javac HelloWorld.java

If there are no syntax errors in your source code, a file named


HelloWorld.class is created. You do not see anything special
happen. However, the file you just created contains the byte-
code for the Hello World program. If there are syntax errors,
you will see error messages on the screen. In that case, you
need to go back to Notepad to fix the errors, save the source
code file again, and recompile until there are no syntax errors
remaining. Syntax errors alert you to mistakes in your source
code and also where they are located in your program.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 An Introduction to Java and the Java Programming Environment

6. After the program is compiled, you can use the dir com-
At this point in mand to display a directory listing to see the file named
your program- HelloWorld.class. To execute the dir command, you type
ming career, dir at the command prompt. For example, if your source
don’t expect
code file is located at C:\My Program\Testing, the command
to understand
the contents of a .class
prompt and dir command should look like this:
10
file if you open one using C:\My Program\Testing>dir. The HelloWorld.class
a text editor such as file should be in the same directory as the source code file,
Notepad. HelloWorld.java.

Step 3 in the development cycle is executing the Java program. You’ll


learn about that next.

Executing a Java Program


As you know, a computer can understand only machine code (1s
and 0s), so a Java program must eventually be transformed from
bytecode into machine code before it can be executed. The Java
Virtual Machine (JVM) is an interpreter that is responsible for
transforming bytecode into machine code and then executing that
machine code.
There are many JVMs available from different vendors and written
for different purposes. For example, Web browsers, such as Internet
Explorer and Mozilla Firefox, contain a JVM. There is a JVM for the
Windows operating system, another for the Mac operating system,
and yet another for the Linux operating system. You will most likely
use the Windows JVM when you execute your Java programs. The
name of the JDK utility you use to transform bytecode and execute
your Java programs is java.
To execute the Hello World program, do the following:
You must be 1. Open a Command Prompt window. To do this in Windows
in the same XP, Vista, or Windows 7, click the Start button, point to All
directory that Programs, click Accessories, and then click Command
contains your
Prompt. Change to the file path containing your source code
.class file
when you execute the
file, if necessary, and then enter the following command:
program. java HelloWorld

2. When the program executes, the words “Hello World.” appear


in a Command Prompt window.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
The Java Development Cycle

Figure 1-3 illustrates the steps involved in compiling HelloWorld.java


using the javac compiler, executing the dir command to verify that
the file HelloWorld.class was created, and executing the Hello
World program using the java interpreter.

11

Figure 1-3 Compiling and executing the Hello World program

Exercise 1-1: Understanding Java Utilities


In this exercise, assume you have written a Java program and stored
your source code in a file named MyFirstJavaProgram.java. Then,
answer Questions 1–3.

1. What is the name of the class stored in this file?

2. What command would you use to compile the source code?

3. What command would you use to execute the program?

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 An Introduction to Java and the Java Programming Environment

LAB 1.1 Understanding Java


Utilities
In this lab, you compile and execute a prewritten Java pro-
gram, and then answer Questions 1–6.
12
1. Open the source code file named Programmer.java using
Notepad or the text editor of your choice.
2. Save this source code file in a directory of your choice, and
then change to that directory.
3. Compile the source code file. There should be no syntax
errors. Record the command you used to compile the source
code file.

4. Execute the program. Record the command you used to exe-


cute the program, and also record the output of this program.

5. Modify the class so that it displays “I am learning how


to program in Java.,” and then change the class name to
JavaProgrammer. Save the file as JavaProgrammer.java.
Compile and execute the program.
6. Mo dify the JavaProgrammer class so that it prints two lines
of output. Change the class name to GoodLuck. Add a second
output statement that displays “Good Luck!” Save the modi-
fied file as GoodLuck.java. Compile and execute the program.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Variables, Constants,
CHAPTER 2
Operators, and
Writing Programs
Using Sequential
Statements

After studying this chapter, you will be able to:

 Name variables and use appropriate data types


 Declare and initialize variables
 Understand and use unnamed and named constants
 Use arithmetic operators in expressions
 Use assignment operators in assignment statements
 Write Java comments
 Write programs using sequential statements and interactive
input statements

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 2 Variables, Constants, Operators, and Sequential Statements

In this chapter, you learn about writing programs that use variables,
constants, and arithmetic operators, and that receive interactive
input from a user of your programs. We begin by reviewing variables
and constants and learning how to use them in a Java program. You
should do the exercises and labs in this chapter only after you have
finished Chapters 2 and 3 of your book, Programming Logic and
14
Design, Seventh Edition, by Joyce Farrell.

Variables
As you know, a variable is a named location in the computer’s
memory whose contents can vary (thus the term variable). You use
a variable in a program when you need to store values. The values
stored in variables often change as a program executes.
In Java, you must declare variables before you can use them in a
program. Declaring a variable is a two-part process: first you give
the variable a name, and then you specify its data type. You’ll learn
about data types shortly. But first, we’ll focus on the rules for naming
variables in Java.

Variable Names
A variable is Variable names in Java can consist of letters, numerical digits, a dollar
sometimes sign, and the underscore character, but they cannot begin with a digit.
referred to as
an identifier. You cannot use a Java keyword for a variable name. As you learned in
Chapter 1 of this book, a keyword is a word with a special meaning
in Java. The following are all examples of legal variable names in Java:
my_var, num6, intValue, and frstName. Table 2-1 lists some examples
of invalid variable names, and explains why each is invalid.

By convention,
Name of Variable Explanation
variable
names in Java 3wrong Invalid because it begins with a digit
begin with a $don’t Invalid because it contains a single quotation mark
lowercase
public Invalid because it is a Java keyword
letter; all other words in
the name begin with an Table 2-1 Invalid variable names
uppercase letter—for
example, frstName.
You cannot include When naming variables, keep in mind that Java is case sensitive—
spaces between the in other words, Java knows the difference between uppercase and
words in a variable name. lowercase characters. Tha t means value, Value, and VaLuE are three
different variable names in Java.
In Java, variable names can be as long as you want. A good rule is to
give variables meaningful names that are long enough to describe

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Variables

how the variable is used, but not so long that you make your program
hard to read or cause yourself unnecessary typing. For example, a
variable named frstName will clearly be used to store someone’s first
name. The variable name freshmanStudentFirstName is descriptive
but inconveniently long; the variable name fn is too short and not
meaningful.
15

Java Data Types


In addition to specifying a name for a variable, you also need to
specify a particular data type for that variable. A variable’s data type
dictates the amount of memory that is allocated for the variable and
the type of data that you can store in the variable. There are many
different kinds of data types, but in this book we will focus on the
most basic kind of data types, known as primitive data types. Ther e
are eight primitive data types in Java: byte, short, int, long, foat,
double, char, and boolean. Some of these data types (such as short,
int, long, double, and foat) are used for variables that will store
numeric values, and are referred to as numeric data types. The others
have specialized purposes. For example, the boolean data type is used
to store a value of either true or false.
You will not use all of Java’s primitive data types in the programs you
write in this book. Instead, you will focus on two of the numeric data
types (int and double). The int data type is used for values that are
whole numbers. For example, you could use a variable with the data In Program-
type int to store someone’s age (for example, 25) or the number of ming Logic
students in a class (for example, 35). A variable of the int data type and Design,
consists of 32 bits (4 bytes) of space in memory. You use the data type Seventh
Edition, the
double to store a floating-point value (that is, a fractional value), such
data type num is used to
as the price of an item (2.95) or a measurement (2.5 feet). A vari- refer to all numeric data
able of the double data type consists of 64 bits (8 bytes) of space in types; a distinction is not
memory. You will learn about using other data types as you continue made between int and
to learn more about Java in subsequent courses. double as it is in Java.

The int and double data types will be adequate for all the numeric
variables you will use in this book. But what about when you need to
store a group of characters (such as a person’s name) in a variable?
In programming, we refer to a group of one or more characters as a
string. An example of a string is the last name “Wallace” or a product
type such as a “desk”. There is no primitive data type in Java for stor-
ing strings; instead, they are stored in an object known as a String
object. In addition to working with the int and double data types in
this book, you will also work with Strings.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 2 Variables, Constants, Operators, and Sequential Statements

Exercise 2-1: Using Java Variables, Data Types,


and Keywords
In this exercise, you use what you have learned about naming Java
variables, Java data types, and keywords to answer Questions 1–2.
16
1. Is each of the following a legal Java variable name? (Answer
“yes” or “no.”)
myIDNumber this_is_a_var NUMBER
yourIDNumber number $number
short 110number foatNum
May13 One Number Number

2. What data type (int, double, or String) is appropriate for


storing each of the following values?
A person’s weight in pounds.
The amount of your rent payment.
Your mother’s maiden name.
The amount of interest on a loan, such as 10%.
The number of classes you are taking.

Declaring and Initializing Variables


Now that you understand the rules for naming a variable, and you
understand the concept of a data type, you are ready to learn how to
declare a variable. In Java, you must declare all variables before you
can use them in a program. When you declare a variable, you tell
the compiler that you are going to use the variable. In the process of
declaring a variable, you must specify the variable’s name and its data
type. Declaring a variable tells the compiler that it needs to reserve
a memory location for the variable. A line of code that declares a
variable is known as a variable declaration. The Java syntax for
a variable declaration is as follows:
dataType variableName;

For example, the declaration statement int counter; declares a


variable named counter of the int data type. The compiler reserves
the amount of memory space allotted to an int variable (32 bits, or
4 bytes) for the variable named counter. The compiler then assigns
the new variable a specific memory address. In Figure 2-1, the
memory address for the variable named counter is 1000, although
you wouldn’t typically know the memory address of the variables
included in your Java programs.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Declaring and Initializing Variables

int counter;

counter (variable name) another variable


value of counter value of the next variable
first second third fourth
byte byte byte byte
17
1000 (The memory address is assigned by 1004 (This is the next available memory address
the compiler; you cannot assign the memory after counter because 4 bytes [1000, 1001,
address yourself.) 1002, and 1003] have been reserved for the
variable named counter.)

Figure 2-1 Declaration of variable and memory allocation

You can also initialize a Java variable when you declare it. When you Numeric
initialize a Java variable, you give it an initial value. For example, variables are
automatically
you can assign an initial value of 8 to the counter variable when you
initialized to
declare it, as shown in the following code: zero (0),
int counter = 8; unless you specify a
different value.
You can also declare and initialize variables of data type double and
String variables as shown in the following code:
double salary;
double cost = 12.95;
String frstName;
String homeAddress = "123 Main Street";

You can declare more than one variable in one statement as long as
they have the same data type. For example, the following statement
declares two variables, named counter and value. Both variables are
of the int data type.
int counter, value;

Exercise 2-2: Declaring and Initializing


Java Variables
In this exercise, you use what you have learned about declaring and
initializing Java variables to answer Questions 1–2.

1. Write a Java variable declaration for each of the following.


Use int, double, or String and choose meaningful variable
names.
Declare a variable to store a product number (1 – 1000).

Declare a variable to store the number of feet in a yard.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 2 Variables, Constants, Operators, and Sequential Statements

Declare a variable to store a temperature (0.0 – 130.00).

Declare a variable to store the name of your home town.

18 2. Declare and initialize variables to represent the following


values. Use int, double, or String and choose meaningful
variable names.
Your shoe size (8.5).
The number of days in a leap year.
The name of your cat, “Yogi”.
Your cell phone number (999-999-9999).

LAB 2.1 Declaring and Initializing


Java Variables
In this lab, you declare and initialize variables in a Java
program provided with the data files for this book. The
program, which is saved in a file named NewAge.java, calculates your
age in the year 2060.
1. Open the source code file named NewAge.java using Notepad
or the text editor of your choice.
2. Declare an integer variable named newAge.
3. Declare and initialize an integer variable named currentAge.
Initialize this variable with your current age.
4. Declare and initialize an integer variable named currentYear.
Initialize this variable with the value of the current year. Use
four digits for the year.
5. Save this source code file in a directory of your choice, and
then make that directory your working directory.
6. Compile the source code file NewAge.java.
7. Execute the program. Record the output of this program.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Constants

Constants
As you know, a constant is a value that never changes. In Java, you
can use both unnamed constants as well as named constants in a
program. You’ll learn about named constants shortly. But first, we’ll
focus on unnamed constants.
19

Unnamed Constants
Computers are able to deal with two basic types of data: text and
numeric. When you use a specific numeric value, such as 35, in a
program, you write it using the numbers, without quotation marks.
A specific numeric value is called a numeric constant because it
does not change; a 35 always has the value 35. When you use a spe-
cific text value, or string of characters, such as “William,” you enclose
the string constant in double quotation marks. Both of the preced-
ing examples, 35 and “William,” are examples of unnamed constants
because they do not have specified names as variables do.

Named Constants
In addition to variables, Java allows you to create named constants. A
named constant is similar to a variable, except it can be assigned a
value only once. You use a named constant when you want to assign a
name to a value that will never be changed when a program executes.
By convention,
To declare a named constant in Java, you use the keyword fnal, fol- in Java the
lowed by the data type, followed by the name of the constant. Named names of
constants must be initialized when they are declared, and their con- constants are
tents may not be changed during the execution of the program. For written in all
example, the following statement declares an int constant named uppercase letters. This
makes it easier for you to
MAX_STUDENTS and initializes MAX_STUDENTS with the value 35.
spot named constants in
fnal int MAX_STUDENTS = 35; a long block of code.

Exercise 2-3: Declaring and Initializing


Java Constants
In this exercise, you use what you have learned about declaring and
initializing Java constants to answer the question.
1. Declare and initialize constants to represent the following val-
ues. Use int, double, or String and choose meaningful names.
The price of a burger is $4.95.
The number of days in October is 31.
The name of your cat is “Yogi”.
The length of a football field in yards is 100.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 2 Variables, Constants, Operators, and Sequential Statements

LAB 2.2 Declaring and Initializing


Java Constants
In this lab, you declare and initialize constants in a Java
program provided with the data files for this book. The
20 program, which is saved in a file named NewAge2.java, calculates
your age in the year 2060.
1. Open the source code file named NewAge2.java using
Notepad or the text editor of your choice.
2. Declare a constant named YEAR and initialize YEAR with the
value 2060.
3. Edit the following statement so that it uses the constant
named YEAR:
newAge = currentAge + (2060 − currentYear);

4. Edit the following statement so that it uses the constant


named YEAR:
System.out.println("I will be" + newAge + "in 2060.");

5. Save this source code file in a directory of your choice, and then
make that directory your working directory.
6. Compile the source code file NewAge2.java.
7. Execute the program. Record the output of this program.

Arithmetic and Assignment Operators


After you declare a variable, you can use it in various tasks. For
example, you can use variables in simple arithmetic calculations,
such as adding, subtracting, and multiplying. You can also perform
other kinds of operations with variables, such as comparing one
variable to another to determine which is greater.
In order to write Java code that manipulates variables in this way, you
need to be familiar with operators. An operator is a symbol that tells
the computer to perform a mathematical or logical operation. Java
has a large assortment of operators. We begin the discussion with a
group of operators known as the arithmetic operators.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Arithmetic and Assignment Operators

Arithmetic Operators
Arithmetic operators are the symbols used to perform arithmetic
calculations. You are probably already very familiar with the arithme-
tic operators for addition (+) and subtraction (−). Table 2-2 lists and
explains Java’s arithmetic operators.
21

Operator Name
and Symbol Example Comment
Addition + num1 + num2
Subtraction − num1 − num2
Multiplication * num1 * num2
Division / 15/2 Integer division; result is 7; fraction is truncated
15.0 / 2.0 Floating-point division; result is 7.5
15.0 / 2 Floating-point division because one of the operands is
a floating-point number; result is 7.5
Modulus % hours % 24 Performs division and finds the remainder; result is 1
if the value of hours is 25
Unary plus + +num1 Maintains the value of the expression; if the value of
num1 is 3, then +num1 is 3
Unary minus − −(num1 − num2) If value of (num1 − num2) is 10, then
−(num1 − num2) is −10

Table 2-2 Java arithmetic operators

You can combine arithmetic operators and variables to create


expressions. The computer evaluates each expression, and the result
is a value. To give you an idea of how this works, assume that the
value of num1 is 3 and num2 is 20, and that both are of data type int.
With this information in mind, study the examples of expressions and
their values in Table 2-3.

Expression Value Explanation


num1 + num2 23 3 + 20 = 23
num1 − num2 −17 3 − 20 = −17
num2 % num1 2 20 / 3 = 6 remainder 2
num1 * num2 60 3 * 20 = 60
num2 / num1 6 20 / 3 = 6 (remainder is truncated)
−num1 −3 Value of num1 is 3, therefore −num1 is −3
Table 2-3 Expressions and values

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 2 Variables, Constants, Operators, and Sequential Statements

Assignment Operators and the Assignment


Statement
Another type of operator is an assignment operator. You use an
assignment operator to assign a value to a variable. A statement that
assigns a value to a variable is known as an assignment statement.
22
In Java, there are several types of assignment operators. The one you
will use most often is the = assignment operator, which simply assigns
a value to a variable. Table 2-4 lists and explains some of Java’s assign-
ment operators.

Operator Name
and Symbol Example Comment
Assignment = count = 5; Places the value on the right side into the memory
location named on the left side.
Initialization = int count = 5; Places the value on the right side into the memory
location named on the left side when the variable
is declared.
Assignment += num += 20; Equivalent to num = num + 20;
Assignment −= num −= 20; Equivalent to num = num − 20;
Assignment *= num *= 20; Equivalent to num = num * 20;
Assignment /= num /= 20; Equivalent to num = num / 20;
Assignment %= num %= 20; Equivalent to num = num % 20;
Table 2-4 Java assignment operators

When an assignment statement executes, the computer evaluates


the expression on the right side of the assignment operator and then
assigns the result to the memory location associated with the vari-
able named on the left side of the assignment operator. An example of
an assignment statement is shown in the following code. Notice that
the statement ends with a semicolon. In Java, assignment statements
always end with a semicolon.
answer = num1 * num2;

This assignment statement causes the computer to evaluate the


expression num1 * num2. After evaluating the expression, the com-
puter stores the results in the memory location associated with
answer. If the value stored in the variable named num1 is 3, and the
value stored in the variable named num2 is 20, then the value 60 is
assigned to the variable named answer.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Arithmetic and Assignment Operators

Here is another example:


answer += num1;

This statement is equivalent to the following statement:


answer = answer + num1;

If the value of answer is currently 10 and the value of num1 is 3, 23


then the expression on the right side of the assignment statement
answer + num1; evaluates to 13, and the computer assigns the value
13 to answer.

Precedence and Associativity


Once you start to write code that includes operators, you need to be
aware of the order in which a series of operations is performed. In
other words, you need to be aware of the precedence of operations
in your code. Each operator is assigned a certain level of precedence.
For example, multiplication has a higher level of precedence than
addition. So in the expression 3 * 7 + 2, the 3 * 7 would be mul-
tiplied first; only after the multiplication was completed would the 2
be added.
But what happens when two operators have the same precedence?
The rules of associativity determine the order in which operations
are evaluated in an expression containing two or more operators with
the same precedence. For example, in the expression, 3 + 7 − 2,
the addition and subtraction operators have the same precedence.
As shown in Table 2-5, the addition and subtraction operators have
left-to-right associativity, which causes the expression to be evaluated
from left to right (3 + 7 added first; then 2 is subtracted). Table 2-5
shows the precedence and associativity of the operators discussed in
this chapter.

Operator Name Operator Symbol Order of Precedence Associativity


Parentheses () First Left to right
Unary − + Second Right to left
Multiplication, division, * / % Third Left to right
and modulus
Addition and subtraction + − Fourth Left to right
Assignment = += −= Fifth Right to left
*= /= %=

Table 2-5 Order of precedence and associativity

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 2 Variables, Constants, Operators, and Sequential Statements

As you can see in Table 2-5, the parentheses operator, ( ), has the
highest precedence. You use this operator to change the order in
which operations are performed. Note the following example:
average = test1 + test2 / 2;

The task of this statement is to find the average of two test scores. The
24 way this statement is currently written, the compiler will divide the value
in the test2 variable by 2, and then add it to the value in the test1 vari-
able. So, for example, if the value of test1 is 90 and the value of test2
is 88, then the value assigned to average will be 134, which is obviously
not the correct average of these two test scores. By using the parenthe-
ses operator in this example, you can force the addition to occur before
the division. The correct statement looks like this:
average = (test1 + test2) / 2;

In this example, the value of test1, 90, is added to the value of test2,
88, and then the sum is divided by 2. The value assigned to average,
89, is the correct result.

Exercise 2-4: Understanding Operator


Precedence and Associativity
In this exercise, you use what you have learned about operator pre-
cedence and associativity in Java. Study the following code and then
answer Questions 1–2.
// This program demonstrates the precedence and
// associativity of operators.
public class Operators
{
public static void main(String args[])
{
int number1 = 10;
int number2 = 4;
int number3 = 16;
int answer1, answer2, answer3;
int answer4, answer5, answer6;

answer1 = number1 * number2 + number3;


System.out.println("Answer 1: " + answer1);

answer2 = number1 * (number2 + number3);


System.out.println("Answer 2: " + answer2);

answer3 = number1 + number2 − number3;


System.out.println("Answer 3: " + answer3);

answer4 = number1 + (number2 − number3);


System.out.println("Answer 4: " + answer4);

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Arithmetic and Assignment Operators

answer5 = number1 + number2 * number3;


System.out.println("Answer 5: " + answer5);

answer6 = number3 / number2;


System.out.println("Answer 6: " + answer6);
System.exit(0);
}
} 25

1. What are the values of answer1, answer2, answer3, answer4,


answer5, and answer6?

2. Explain how precedence and associativity affect the result.

LAB 2.3 Arithmetic and Assignment


Operators
In this lab, you complete a partially written Java program
that is provided along with the data files for this book.
The program, which was written for a furniture company, prints
the name of the furniture item, its retail price, its wholesale price, the
profit made on the piece of furniture, a sale price, and the profit made
when the sale price is used.
1. Open the file named Furniture.java using Notepad or the
text editor of your choice.
2. The file includes variable declarations and output statements.
Read them carefully before you proceed to the next step.
3. Design the logic that will use assignment statements to first
calculate the profit, then calculate the sale price, and finally
calculate the profit when the sale price is used. Profit is defined
as the retail price minus the wholesale price. The sale price is
20% deducted from the retail price. The sale profit is defined as
the sale price minus the wholesale price. Perform the appropri-
ate calculations as part of your assignment statements.
4. Save the source code file in a directory of your choice, and
then make that directory your working directory.
5. Compile the program.

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Discovering Diverse Content Through
Random Scribd Documents
passions et par la vie du monde. Et en cet instant même, avec le
psalmiste, elles chantent pour la désolée :
« Pourquoi vous lever avant la lumière ? Levez-vous après avoir
goûté le repos, vous qui mangez le pain de la douleur !… »

— Mais, s’écria Stéphanie, il fallait me réveiller, comme hier !


Elle n’avait ouvert les yeux qu’au grand jour, après neuf heures,
et maintenant elle s’étonnait qu’à peine debout Madeleine lui
apportât un petit déjeuner appétissant, en s’excusant qu’il
ressemblât beaucoup au léger souper de la veille. Par deux fois déjà,
elle avait entr’ouvert la porte pour prendre les ordres, et, devant le
persistant sommeil de la retraitante, elle était repartie sur la pointe
des pieds.
— Je ne voudrais pas d’un régime de faveur, insista Stéphanie…
C’est pour faire une retraite que je suis venue ici.
Le rire clair de la postulante égaya la petite chambre,
interloquant un peu la comtesse.
— N’ayez pas peur, Madame… Vous ferez une retraite. Fiez-vous
pour cela au Père Orban.
— C’est l’aumônier ?
— Nous l’appelons : le Père Spirituel.
Et tout de suite elle changea de sujet.
— N’est-ce pas, Madame, que le parc est joli ?
Par l’unique fenêtre ouverte, une imposante découverte de
pelouses et d’ombrages fermait de tous côtés l’horizon, isolant le
couvent de la plaine qui l’environnait.
Les yeux de la comtesse avaient suivi ceux de Madeleine. Oui… le
dessin des allées avait du style et les essences des arbres de la
variété. « Mais il n’y a pas de fleurs ! » pensait-elle.
— Rien que celles que fait pousser le bon Dieu dans les prairies,
et un petit coin du potager où l’on cultive de quoi parer l’autel les
jours de fête, dit Madeleine. Vous aurez assez de pain grillé,
Madame ?
— Oh ! bien assez.
— Je vous laisse déjeuner… Si vous désirez assister à la messe,
un Père jésuite français, qui vient d’arriver, dira la sienne à onze
heures. Je viendrai vous chercher, n’est-ce pas ?
— Je serai prête.
Restée seule, Stéphanie commença de beurrer ses rôties et de
déjeuner avec appétit. Le profond et calme sommeil, depuis Matines,
avait coupé la fièvre ; un sommeil tel qu’elle ne se souvenait pas d’en
avoir goûté de pareil depuis bien des mois ; elle en était encore
engourdie. Tout d’un coup, jetant de nouveau un regard sur les
verdures du parc, parées d’un clair soleil qui dissipait la buée du
matin, elle songea à la phrase de Madeleine, au sujet des fleurs :
« Est-ce que je lui avais fait la remarque qu’il n’y en avait pas ?
Mais non… je n’avais rien dit… J’avais pensé, seulement… »
Un peu de ce trouble imprécis que la jeune fille lui avait causé la
veille par ses paroles et toute sa façon d’être lui parcourut les nerfs :
pas un malaise, mais une incertitude, une attente proche de
l’anxiété. Elle s’en gourmanda, comme d’une faiblesse.
« Après tout, je l’ai peut-être dit. Et si je ne l’ai pas dit, il n’était
pas difficile de comprendre ce que je pensais… Elle m’a paru
d’ailleurs beaucoup plus ordinaire ce matin, cette enfant. Sauf le
béguin, on aurait dit d’une petite femme de chambre campagnarde.
Le déjeuner achevé, Stéphanie se sentit désœuvrée et souhaita
le retour de Madeleine. Le minuscule ovale de diamants qui cernait à
son poignet le cadran des heures disait : dix heures moins vingt-
cinq. Mais à peine l’eût-elle regardé que la voix profonde,
confidentielle, de l’horloge du couvent détailla les trois coups de dix
heures moins le quart. Stéphanie accorda minutieusement sa montre
à l’horloge. Elle eut tort. Cette montre, seul bijou qu’elle eût emporté
avec elle dans sa retraite, que de fois, se penchant vers son poignet,
le Maître de son destin l’avait consultée : car lui-même ne portait
jamais l’heure avec lui. Ah ! la mémoire d’un geste familier, quelle
évocation ! Souvent, après ce regard pour cueillir le temps, il
approchait ses lèvres de la ligne céruléenne que barrait la gourmette
de platine et, ayant dit : « Je vais boire tout ton sang », de sa
bouche collée à l’artère, il aspirait doucement, lentement, à petits
coups, et son amante croyait alors sentir la liqueur rouge de sa vie
couler de son bras dans la gorge de l’amant : elle défaillait, elle se
pâmait, elle se fondait en lui, criant grâce…

— Madame, le Père est à la sacristie.


Vibrante encore au point de s’appuyer à la table pour garder son
équilibre, elle suivit Madeleine.
La chapelle où le jésuite français allait dire sa messe était
spécialement affectée aux retraitantes dites « de passage », celles
qui, comme Stéphanie, s’annonçaient simplement pour une ou deux
semaines. Elle était de dimensions moyennes et d’aspect froid, avec
son faux appareil de pierre sur les murailles et sur la voûte ; son
chemin de croix, son chœur, son maître autel, du style le plus
strictement moderne, et moderne de série. Pourtant un grand cadre
à larges bords dorés, formant le fond du maître autel, enfermait un
tableau assez bien traité dans le style de 1850 : il représentait une
descente de croix… Stéphanie, pénétrant dans la chapelle avec
Madeleine, constata qu’elle n’était peuplée que de chaises vides ;
mais, au moment même où l’officiant sortait de la sacristie, précédé
d’un minuscule enfant de chœur (le fils du jardinier, dit Madeleine),
une dame âgée, appuyée de la main droite sur une béquille et
donnant à une moniale son bras gauche qui ne lâchait point une
autre béquille, vint s’asseoir au second rang. Stéphanie, comme le
publicain, s’était instinctivement réfugiée vers les derniers rangs, et
Madeleine l’y avait suivie.
Quelle sécheresse désespérée habitait son cœur, tandis qu’elle
parcourait des yeux les pages de l’eucologe que sa petite compagne
lui avais mis, ouvert où il convenait, entre les mains ! Le trouble
sensuel de tout à l’heure s’était apaisé, ou plutôt arrêté net dès
qu’elle avait perçu la présence de Madeleine, mais il la laissait brisée,
inerte. Nul souhait de raviver le passé tumultueux : oh ! non !… Pas
besoin de résister à une tentation ; elle s’en écartait ainsi que d’un
incendie redoutable, et par surprise seulement, le feu tout à l’heure
avait fait irruption sur elle.
« J’ai trop souffert, pensait-elle… Si c’était à recommencer, je
partirais encore… Mais que suis-je venue faire ici ?… Cette chapelle
est sinistre, ce prêtre est un passant comme moi ; je ne le reverrai
jamais. On ne s’occupe pas de moi, ou du moins on s’en occupe
comme d’une voyageuse dans une pension de famille, pour me
coucher et me nourrir. Ce n’est pas cela que je suis venue
chercher ! »
L’enfant de chœur porta le missel de la droite à la gauche de
l’autel : Stéphanie et Madeleine se mirent debout. L’Évangile fini,
elles s’assirent ; leurs yeux se rencontrèrent. Stéphanie se sentit
rougir, comme si sa voisine avait lu dans ses pensées. « Elle a
vraiment un regard extraordinaire, qui vous pénètre et qui vous
émeut. Singulier petit être ! Allons ! tâchons de prier… »
Elle lut consciencieusement une page environ d’eucologe, puis
releva les yeux sur Madeleine. La jeune fille avait déposé son livre
sur le siège du prie-Dieu, et, assise, semblait avoir rivé son regard
au grand tableau qui formait le fond de l’autel. Le Christ, descendu
de la Croix, était étendu par terre, entre la Vierge et sainte
Madeleine : les autres saintes femmes formaient en recul un groupe
indistinct. Une sorte de linceul aux plis tourmentés couvrait la partie
inférieure du corps jusqu’au creux du thorax : la poitrine, les bras,
les épaules étaient nus. Couché sur le dos, le buste légèrement
dressé et incliné vers le spectateur, le divin supplicié avait les bras
allongés le long du corps ; sa tête pendait douloureusement sur son
épaule gauche. La couronne d’épines, détachée de ses cheveux,
gisait à terre : du sang et de la boue souillaient sa barbe, qui,
comme les cheveux, était d’un brun roux. Le sang coagulé noircissait
les lèvres de la blessure ouverte par la lance du soldat romain ; les
paupières couvraient les yeux, mais on eût dit qu’un regard de
désolation coulait entre les cils qui ne se rejoignaient pas
exactement. Ce n’était certes pas un chef-d’œuvre ; mais c’était un
honorable travail dans le style de Fromentin, et, si la douleur des
saintes femmes était passablement froide et poncive, le buste
transverbéré avait de la réalité douloureuse. Et le pinceau de
l’artiste, en fixant sur la toile ces membres roides et cette face
glacée, cette peau vide de sang, cette blessure qui semblait vivre
seule encore dans le cadavre, ce regard invisible mais sensible entre
les paupières défaillantes, avait ressenti et rendu toute l’inspiration
dont il était capable.
L’attention de Stéphanie s’attachait moins au tableau qu’à
Madeleine regardant le tableau. La jeune fille avait les mains non
pas jointes, mais allongées l’une contre l’autre entre ses genoux
serrés. Son buste se penchait en avant, et sa tête aussi s’avançait un
peu de biais, comme il arrive quand on prête l’oreille. L’immobilité
était absolue, impressionnante. Stéphanie remarqua que les yeux,
fixés sur un point du tableau, ne remuaient pas les prunelles et que
les cils ne clignaient pas. Elle eut un sentiment d’angoisse, presque
de peur, et murmura assez haut pour être entendue de sa voisine :
« Madeleine ! » L’enfant, évidemment absente d’esprit, n’entendit
pas. Alors Stéphanie étendit la main et frôla le haut du bras qui était
à sa portée. Madeleine ne remua pas : elle n’avait pas senti
l’attouchement. « Mais c’est de l’hypnotisme… de la catalepsie !… »
pensa Stéphanie… Le gamin en soutanelle rouge, en cet instant, fit
tinter la clochette pour annoncer le Sanctus… Madeleine rompit
aussitôt et très naturellement sa pose extatique, reprit son eucologe
sur le prie-Dieu et s’agenouilla. Stéphanie, tracassée d’une singulière
impatience, s’agenouilla sur le prie-Dieu voisin. Elle regarda à son
tour l’entaille du flanc divin, et l’image lui parut émouvante…
« Comme ces troubles mystiques sont contagieux, pensa-t-elle, car
elle gardait un sens critique en éveil, avec une nuance de méfiance
hostile… Moi qui n’ai rien de mystique, je suis remuée par ce que je
viens de voir, et cette médiocre peinture est tout près de
m’attendrir. » Elle observa de nouveau Madeleine ; celle-ci lisait son
office attentivement, mais comme n’importe quel fidèle attentif.
Quand les trois coups du Sanctus résonnèrent, elle inclina son visage
dans l’eucologe entre-bâillé.
La messe terminée, toutes les deux ensemble remontèrent dans
la chambre de Stéphanie.
— La Sœur Incarnation, qui est directrice des retraites, dit
Madeleine, désirerait causer avec vous avant Complies, c’est-à-dire
vers quatre heures. Est-ce que cela vous convient ?
— Bien sûr. Je suis à sa disposition.
— Je vous conduirai chez elle. Notre Mère Supérieure ne sera pas
visible aujourd’hui, mais demain. Elle est elle-même en retraite
spéciale de trois jours pour sa fête patronale. Notre Père Spirituel
vous recevra après-demain dans la matinée.
« A la bonne heure, pensa Stéphanie, on commence à
s’apercevoir de ma présence. » Et tout haut :
— Le Père me recevra en confession ?
— Je ne crois pas… Il vous recevra chez lui et vous donnera des
directions.
— Et d’ici là, qu’aurai-je à faire ?
— Mais… Ce qu’il vous plaira… Vous lirez… vous prierez… Vous
vous promènerez dans la partie du parc réservée aux dames « de
passage ». Et, si je ne vous importune pas, je suis là pour causer
avec vous, pour vous renseigner, sauf aux heures d’office, où je
rejoins nos sœurs.
— Je ne puis pas vous accompagner aux offices ?
— C’est notre Père Spirituel, après avoir causé avec vous, qui en
décidera.
A partir de ce moment, Stéphanie s’engagea dans un chemin
d’heures — une cinquantaine d’heures environ — qui lui parut
interminablement long et parcouru avec une insupportable lenteur.
Or, plus tard, lorsque furent accomplis les événements que ces
heures préparaient, elle dut reconnaître que nulles autres de sa vie
n’avaient été plus chargées d’influence, plus concentrées vers la
gestation de l’avenir, plus décisives. C’est que le procédé de la
nature, pour transformer le corps ou l’esprit, n’a rien de soudain ni
de romanesque : elle ne « fait pas de bonds », comme a dit Leibniz.
Newton découvre la loi de la gravitation en un moment où sa pensée
est comme en veilleuse, où ses yeux suivent, sans l’observer, la
cadence d’un objet suspendu. Nos grandes crises physiologiques se
nouent et se dénouent dans l’organisme interne à notre insu ; notre
vie ou notre sort sont ainsi décidés parfois, tandis que nous bâillons
d’indifférence et d’ennui… Pendant ces cinquante heures, Stéphanie
contraignit bien des bâillements, et en laissa d’autres exhaler entre
ses lèvres contractées la lassitude, l’anxiété : elle attendait quelque
chose qui ne venait point ; elle se demandait si ce quelque chose
viendrait jamais, et, circonstance péjorative, elle ne savait pas elle-
même très bien ce qu’elle attendait… Alors tout, autour d’elle, lui
semblait, sinon vide, au moins impondérable, ignorant que ce vide,
cet impondérable deviendraient un foyer éclatant à mesure qu’ils
reculeraient dans le passé… Si un être vivant pouvait traverser
l’étoile Bételgeuse, il ne s’en apercevrait même pas, car elle n’est
qu’une énorme bulle de gaz, et, vue de notre terre, nul joyau plus
éclatant ne brille sur le baudrier d’Orion.
A peine, dans ce voyage morose, quelques étapes s’inscriront
alors dans sa mémoire.
Il y eut la seconde conversation avec Sœur Incarnation. Dans le
parloir, comme la première. Même affabilité que la veille. Juste les
questions nécessaires pour connaître les projets de la retraitante,
diriger sa vie pratique, lui tracer un programme de lectures et
d’exercices. Tout cela, proféré avec mesure et onction, trahissait la
réserve, la consigne. En regagnant sa chambre, Stéphanie pensait :
« On prend des précautions à mon endroit. Pour la Sœur
Incarnation, je ne suis pas une âme à consoler, comme pour cette
charmante Madeleine. Je suis la comtesse d’Armatt, avec son titre,
son rang, sa légende… Peut-être, parmi les dirigeants de la
Quarantaine, aimerait-on mieux que je n’eusse pas frappé à la
porte ; mais enfin, puisque j’y ai frappé, on ne pouvait guère me
refuser l’entrée… Alors, il s’agit de ne pas avancer trop vite, de
rester avec moi dans les pieuses palabres à l’usage de tout le
monde, et de me laisser en observation jusqu’à ce que le Père
Spirituel, qui me semble ici dictateur, décide de mon sort… »
Il y eut l’autre conversation prévue avec la Mère Supérieure.
« Aimable, intelligente, un peu commune, jugea la comtesse au
retour dans sa chambre. Mais sous ses façons avenantes, voire
prévenantes, j’ai perçu la même réserve que m’a opposée Sœur
Incarnation : peut-être même plus de réserve, parce que la
Supérieure a plus de responsabilité… On a reculé mon entrevue avec
le Père Spirituel pour avoir le temps de se renseigner et aussi de
m’étudier. Madeleine est sans doute chargée de cette étude et du
rapport… C’est certain ; je ne peux pas le lui reprocher. Et pourtant
cela cadre si mal avec son allure… »
Car, dans ses heures brumeuses, persistait une clarté :
Madeleine… Elle n’était pas toujours là : les offices la requéraient
plusieurs fois dans la journée. Mais elle donnait à la retraitante tout
ce qu’elle avait de temps libre, ni guindée comme un Mentor, ni
obséquieuse comme une dame de compagnie. Le naturel, avec une
gaîté non feinte, cela semblait être la caractéristique de cette enfant.
« Elle a de la cordialité et de l’aplomb, pensait Stéphanie, la douceur
du ton et la fermeté des propos, et une étonnante indifférence pour
le jugement qu’on portera sur ce qu’elle dit. Elle a l’air d’obéir à une
force intérieure… Quelle sûreté ! Quel équilibre ! L’heureuse jeune
fille !… »
Avec Madeleine, Stéphanie connut les aîtres du couvent, sauf
pour la partie cloîtrée. Elle visita l’hôpital, les divers quartiers de
retraitantes, le parc. Madeleine lui conta que, lors de son entrée à la
Quarantaine, à seize ans, elle avait d’abord été aide-converse, puis
infirmière. Depuis un an seulement on l’affectait au service des
retraitantes. Stéphanie lui demanda :
— Pourquoi n’avez-vous pas fait encore votre profession ?
Sans le moindre embarras, la jeune fille répondit :
— Ma sainte Patronne saura bien me dire le jour où il le faudra.
Et Stéphanie n’osa pas insister.
Le quartier des retraitantes lui parut ressembler à certains
béguinages visités autrefois ; il ne la séduisait guère. « J’aimerais
mieux le cloître », pensa-t-elle. Presque toutes les dames
rencontrées étaient âgées ; plusieurs, infirmes. Mais le parc était
somptueux. Elles n’y virent personne.
— Les dames n’y viennent presque jamais, disait Madeleine… Les
cours de leurs quartiers leur suffisent comme promenade. Et,
d’ailleurs, elles ne sont pas cloîtrées.
Elle, au contraire, connaissait ce vert domaine jusqu’aux
moindres sentiers.
— J’ai été converse, disait-elle en riant… J’ai balayé et ramassé
les feuilles, en novembre… La vie n’était pas ennuyeuse. Presque
tous les jours on allait aux emplettes dans le village, là-bas, de
l’autre côté de la frontière…
— Et à présent, cela ne vous manque pas ?
— Oh ! pas du tout !… Voilà dix-huit mois que je ne suis pas sortie
de la Quarantaine…
— Et si vous vouliez sortir ?…
— Je n’aurais qu’à ouvrir ce verrou (elles passaient en ce moment
devant une porte à un seul vantail pratiquée dans le mur). Au delà
c’est la campagne. Et je pourrais même refermer le verrou du
dehors : voyez, le cadre est disjoint. Que de fois je l’ai fait quand
j’aidais les sœurs converses ! C’est plus court pour gagner le village,
quand on est pressé.
Stéphanie pensait :
« Et moi ? Si je voulais sortir ? Il ne tient qu’à moi… Suis-je déjà,
comme cette enfant, tenue par des liens que je ne commande
plus ? »
Rentrant d’une autre promenade dans le parc, au soir tombant,
elles entendirent des chiens aboyer, comme elles approchaient des
bâtiments.
— Oh ! fit Madeleine, je vais vous présenter mes petits frères.
C’étaient deux molosses formidables, presque identiques de taille
et de poil, gris de fer. Ils se turent dès l’approche de Madeleine et
vinrent ramper à ses pieds, grondant d’amour. Elle leur caressa la
tête.
— Ils sont féroces, dit-elle à la comtesse qui n’osait s’approcher.
On les lâche la nuit, et je vous assure que le parc est en sûreté. Mais
ils me connaissent, et, près de moi, vous n’auriez rien à craindre.
N’est-ce pas, mes petits frères ?…
Ils tiraient sur leur chaîne pour flairer Madeleine et la lécher.
— Allons, soyez sages. Rentrez dans vos niches.
Ils obéirent, silencieux et maussades.
— C’est toujours moi qui les nourris, dit Madeleine.
Si juvénile, presque puérile dans ce qu’elle appelait les heures de
récréation, la postulante n’en accomplissait pas moins sérieusement
sa fonction de monitrice. Stéphanie, distraite, anxieuse, ne l’écoutait
pas toujours dans ce rôle : mais rien ne décourageait ce bon vouloir
actif. Nul ton de prédication, d’ailleurs, nulle pose : mais pas l’ombre
de timidité, et une ténacité aussi douce qu’inflexible. Madeleine ne
faisait jamais allusion aux soucis, aux regrets qui pouvaient
tourmenter la retraitante. Jamais elle ne l’interrogeait. Mais on eût
dit qu’elle en suivait l’action intérieure reflétée sur le visage.
Stéphanie en fut quelque temps gênée : puis elle s’y habitua, et
cette concordance secrète de leurs deux pensées lui fut un
réconfort. Son cœur ne fut plus pincé d’angoisse quand une réplique
de la jeune fille s’adaptait exactement à une idée qu’elle n’avait pas
exprimée, à une sensation qu’elle cachait. Par exemple, comme
l’écume de certains souvenirs d’amour, un soir, montait en elle, et
qu’elle s’y attardait, ne sachant plus s’ils lui faisaient horreur ou s’ils
la tentaient, Madeleine dit : « Les pensées et les images dont nous
ne voulons pas, le démon peut les amener jusqu’au seuil de la cour,
et même les pousser contre le bord de la maison… Mais il dépend de
nous de les empêcher d’entrer. Alors, c’est un plaisir de les entendre,
comme de méchantes bêtes, gratter rageusement aux portes et
essayer de forcer les contrevents… » Et elle éclatait de son jeune
rire, comme si elle se rappelait d’amusants sièges soutenus ainsi
contre le Malin… « Propos de couvent ! se disait Stéphanie : on n’est
pas maître de sa pensée… » Mais, au prochain assaut, la parabole
comique des portes grattées et des contrevents forcés lui revint à la
mémoire, et le flot du passé, roulant ses douleurs moins détestables
que ses bonheurs, recula.
Il y eut encore, dans ces heures lentes, les offices dans la
chapelle froide, les lectures, dans la chambre, des ouvrages édifiants
envoyés par Sœur Incarnation. A la chapelle, Stéphanie souffrait
d’une sorte de paralysie de sa sensibilité, et parfois d’une hostilité
contre le décor environnant, contre les autres retraitantes qu’elle ne
voulait pas connaître, contre le couvent même. C’est là, faisant les
gestes de la prière, qu’elle se sentait le plus près de renoncer à
toute pénitence, de fuir le couvent, de rejoindre le Maître de sa vie…
« Qu’est-ce que je fais ici ?… Ce n’est point ma place… J’ai rêvé une
chose impossible… » A ces moments-là, si Madeleine n’eût pas été à
genoux auprès d’elle, elle serait partie rompant la neuvaine… Mais
Madeleine était là, et déjà son âme avait besoin de cette autre âme
mystérieuse.
Les lectures dans sa chambre retenaient mieux sa pensée,
surtout quand c’était Madeleine qui lisait à haute voix. Madeleine
lisait lentement, avec un léger accent de sa province, mais sans
jamais buter sur une syllabe, et avec une intelligence merveilleuse.
Elles lurent ainsi des pages de l’Imitation, mais Stéphanie en
éprouva une réelle souffrance : elle se sentait si loin de ces régions
spirituelles ! Madeleine s’en aperçut et prit un autre livre. C’était une
Vie de Sainte Thérèse, fondatrice des Carmélites déchaussées,
publiée au X V I I I e siècle par M. l’abbé Godescard, chanoine de Saint-
Honoré. La partie anecdotique et historique de l’ouvrage, surtout
celle qui raconte l’enfance et la jeunesse de la sainte, réussit à
attacher Stéphanie : elle écoutait d’ailleurs avec plus de curiosité
que d’onction. Il y eut une page où l’auteur, interrompant sa
narration, citait un passage tiré des mémoires de son héroïne. Elle y
évoque les difficultés que lui opposa l’oraison, aux débuts de sa vie
conventuelle.
« Je me sentais, dit-elle, attirée par les liens célestes : ceux de la
terre me retenaient captive. Je ne pouvais enfermer mon esprit en
moi-même sans enfermer avec lui mille vanités. Qu’une âme est à
plaindre, de se trouver seule au milieu de tant de périls !… Aussi
conseillerais-je de se lier d’amitié, dans le commencement surtout,
avec des personnes qui pratiquent les mêmes exercices… »
Là, Madeleine, cessant de lire, releva les yeux : son regard gris-
bleu rencontra celui de Stéphanie… « Ah ! pensa celle-ci, des yeux
pareils ne mentent point ! Cette enfant ne me surveille pas ! ne me
trahira pas… Elle m’aime… »
D’un de ces brusques élans que sa nature violente contenait avec
peine sous une apparence de froideur mondaine, elle quitta sa
chaise et, prenant dans ses mains la tête de la jeune fille, elle la
baisa au front.
— Madeleine, dit-elle, il ne faut pas m’abandonner.
Madeleine répondit gravement :
— Quand je vous quitterai, c’est que vous n’aurez plus besoin de
moi.
Cependant les heures lentes naissaient et mouraient l’une après
l’autre. Et le troisième matin, vers dix heures et quart, ce fut la fin
de l’épreuve.
— Si vous voulez, dit Madeleine à Stéphanie, je vais vous
conduire chez le Père Orban. Il aime l’exactitude. Plutôt que d’être
en retard, nous attendrons devant sa porte le coup de dix heures et
demie.
III

Madeleine frappa à la porte. Au lieu du : « Entrez »


qu’inconsciemment guettait Stéphanie, une voix un peu voilée, mais
sonore, répondit :
— Oui !
Madeleine entre-bâilla la porte, juste assez pour avancer le buste
et la tête et dit :
— Mon père, c’est la dame retraitante.
— Qu’elle entre.
Et voilà que Stéphanie fut assise dans un fauteuil de paille assez
confortable, très large de siège, avec un dossier rustique bien ciré et
des accoudoirs plats. Le jour, qui venait du parc, était verdi dans la
pièce par la peinture vert clair des murailles sur lesquelles la fenêtre,
la porte et une alcôve close de rideaux en percale découpaient des
moulures d’un vert plus foncé. Stéphanie vit très nettement cela, et
aussi deux gravures pieuses pendues au mur, un crucifix avec un
buis desséché. Elle ne vit pas, parce qu’elle n’osa pas d’abord se
servir de ses yeux pour le voir, le Père Orban assis dans son fauteuil
de chêne massif devant un bureau-cylindre de chêne massif. Le Père
Orban ne s’était pas levé tout à fait pour l’accueillir ; il avait
seulement ébauché le geste et montré un siège à la visiteuse. Elle
ne l’avait pas encore regardé en face quand elle l’entendit qui lui
disait, d’un ton où ne se marquait ni bienveillance ni malveillance,
d’un ton de fonctionnaire désintéressé mais attentif :
— Vous êtes Madame de Baurens, n’est-ce pas ?
Elle avait tellement perdu la coutume de s’entendre appeler ainsi
qu’elle hésita un moment avant de balbutier :
— Oui… c’est-à-dire… C’est le nom que je portais…
Le Père l’interrompit.
— C’est le nom que l’Église catholique a inscrit sur ses registres
quand vous vous êtes unie, dans votre ville natale, paroisse de
Saint-Elme, à Jean-Marie Roart de Baurens, consul royal.
Stéphanie baissa un peu la tête, sans que ce mouvement
ébauché signifiât distinctement l’acquiescement ou la confusion.
— Ensuite, reprit le prêtre, vous vous êtes séparée de votre mari,
après quelques mois de vie commune. Oui… je sais… Il avait de
graves torts envers vous. Vous avez quitté le pays, et vous avez
vécu, fort dignement, m’a-t-on dit, à l’étranger, gagnant même votre
vie comme… institutrice dans une famille de diplomates. Vous avez
suivi cette famille dans les divers postes où son chef fut nommé
successivement… Et c’est dans le dernier que le prince Paul vous
rencontra et vous fit divorcer.
Un sanglot opprimé par la morsure des dents dans un mouchoir
arrêta le Père, qui jusque-là avait parlé face aux casiers de son
bureau, sans regarder la femme en noir abattue, tapie comme une
blessée sur le fauteuil rustique. Sa voix se timbra un peu plus, fut
moins neutre, plus humaine quand il reprit, cette fois tourné à demi
vers elle :
— Ce n’est pas pour vous humilier, ma fille, que je vous dis tout
cela. Au contraire. C’est pour vous épargner un récit que vous seriez
probablement hors d’état de faire, ou bien… des séries interminables
de questions et de réponses. Je vous dis d’abord ce que je sais de
vous, de votre vie. Ensuite… ensuite je serai bien obligé de vous
interroger. Et… mon Dieu !… m’y voilà… mon savoir est à bout, en ce
qui vous concerne, sauf que la Supérieure m’a fait lire la lettre où
vous postuliez une retraite ici… et aussi (il hésita une seconde)… que
j’ai lu dans le journal, tout à l’heure, une courte dépêche annonçant
que le prince a quitté à son tour sa famille et son pays.
— Il est parti !… fit la retraitante, redressée sur son siège comme
par l’effet d’une explosion toute proche.
Elle osa regarder le Père Orban, et, dans cette figure triangulaire
barrée par un nez un peu oblique et surmontée d’un crâne tondu,
elle rencontra les yeux du moine, d’un bleu de plomb tranché, qui
luisaient dans une peau rougeâtre, tannée, bourgeonnante par
plaques.
Les deux regards se frôlèrent, s’enlacèrent comme un coup
fourré d’épées, et très vite Stéphanie déroba le sien ; une vive
rougeur avait inondé ses joues et son front.
— Cela vous émeut ? reprit le Père avec un peu de sarcasme dans
le ton. Eh bien ! vous avez tort d’être émue. Le départ de votre
époux civil (l’adjectif fut proféré sans le moindre soulignement vocal)
n’a aucun rapport avec le vôtre… La dépêche laisse entendre
discrètement que le prince n’est pas parti seul.
Stéphanie sanglotait presque sans bruit. Puis elle essaya de se
réfréner, balbutiant : « Pardon !… pardon !… »
— Voilà donc la situation, reprit le Père Orban très calme.
Envisageons, n’est-ce pas, les choses telles qu’elles sont. Vous avez
quitté la première le domicile conjugal, pour des raisons que je ne
connais qu’en gros, et sur lesquelles j’aurai des éclaircissements à
vous demander, si vous désirez que je dirige utilement votre
conscience.
A une pause que fit le Père, Stéphanie répondit par un signe
d’assentiment très net.
— Bon !… C’est bien, n’est-ce pas, le 13 juillet dernier que vous
vous êtes libérée ?… Et dans l’intervalle, vous vous êtes arrêtée à
Arnheim, d’où vous avez écrit à la Mère Supérieure et où vous avez
reçu sa réponse ?
Stéphanie acquiesça deux fois.
— Eh bien ! moins de six jours après votre départ, le prince Paul
s’est évadé lui aussi de la cour et du royaume paternels. Une femme
l’accompagnait, ou bien il allait la rejoindre… la dépêche que publie
le journal ne l’indique pas avec précision.
— Je sais qui elle est ! interrompit vivement Stéphanie. Une fille
de théâtre… pas même… une fille de music-hall, sortie des bouges
de Cagliari, qui se fait appeler la Montarena.
— Peu importe, coupa avec une certaine sévérité le Père Orban.
Hors des lois précises que Dieu a établies pour l’union de l’homme et
de la femme, l’importance du péché ne se mesure pas à la quantité
sociale ni même morale du complice.
Il s’arrêta, considéra la pénitente qui tremblait d’émotion ; puis il
reprit avec plus de douceur :
— Dieu vous tiendra compte certainement de ce que vous n’avez
pas attendu d’être vous-même abandonnée pour rompre les liens…
qu’il n’avait pas bénis : ne disons rien de plus pour le moment. Votre
lettre à la Mère Supérieure (écartant un peu son fauteuil de bureau,
il prit son menton aigu dans la paume de sa main gauche et parla
plus lentement) dit, si mes souvenirs sont exacts, que « vous n’avez
pas cru devoir supporter plus longtemps le genre de vie que vous
imposait le prince Paul ».
— Oui, c’est cela, dit Stéphanie. Je ne pouvais plus… je ne
pouvais plus.
— Il faudra me dire ce qui était survenu de nouveau dans votre
ménage, pourquoi ce que vous aviez supporté un certain temps vous
paraissait tout d’un coup insupportable… Non, pas tout de suite, fit-il
en arrêtant de la main une réplique que les lèvres de Stéphanie
allaient proférer… Continuons à bien fixer vos… coordonnées
présentes, comme on dit en géométrie.
Il ne la quittait pas des yeux, maintenant, et ses yeux à peine
allongés, presque ronds, fixés sur la jeune femme, donnaient à celle-
ci l’impression qu’elle était parcourue des pieds à la tête par ce
regard, comme avec une lance un jardinier arrose une plante de la
racine à la cime, et en fait ainsi quelque chose de pénétré par
l’élément humide, quelque chose de plus souple, de plus poreux…
Mais comme pour la plante, de cette pénétration intime et totale
résultait pour Stéphanie une relâche, un bienfait.
Elle écoutait avec soumission, étonnée d’être si vite en confiance
avec ce prêtre inconnu, d’un abord rude, de se sentir avide de
l’entendre comme s’il détenait le secret d’apaiser son cœur
tumultueux, de lui tracer un chemin, de la conduire.
— Voulez-vous me dire d’abord, reprit-il, les conditions exactes
dans lesquelles vous avez rompu votre premier mariage et contracté
le second ?
— Mais… répliqua Stéphanie, j’ai demandé le divorce et il a été
prononcé par le Tribunal aux torts de mon mari. Nous étions séparés
de fait. M. de Baurens, quelques semaines après notre mariage,
avait renoué une vieille liaison… C’est pour cela que j’ai pris la
première occasion de le quitter sans scandale, à l’amiable, en
partant pour l’étranger. L’occasion, ce fut… La femme du ministre de
Suède me connaissait, nous étions très liées… Elle avait une grande
fille à élever. Elle m’offrit de la suivre partout où elle irait avec son
mari.
— Comme institutrice ?
— Comme institutrice de sa fille Gertrude, et aussi pour l’aider
dans la conduite de la maison — elle souffrait de coliques
néphrétiques et souvent devait observer un plein repos… Puis, enfin,
comme amie…
— Et c’est ainsi que vous avez finalement rencontré…?
— Oui.
— Et malgré la situation… honorable… mais enfin… secondaire
qui était la vôtre, le prince héritier vous a remarquée ?
— Il m’a vue pour la première fois à la Légation de Suède, dans
un bal… Il m’a fait danser à plusieurs reprises… Et ensuite, il est
revenu très souvent chez mon amie… chez la femme du ministre.
— Et celle-ci a protégé vos relations avec lui ?
— Mais, mon Père, objecta vivement la jeune femme, jamais rien
ne s’est passé… enfin… le prince a presque tout de suite parlé de
mariage… et alors… naturellement, mon amie l’a encouragé et m’a
encouragée.
— Elle est protestante ? questionna le Père.
— Oui.
— Évidemment… alors…
Il eut un geste évasif qui semblait dire : « Alors… il n’y avait rien
à espérer. »
— Le prince Paul aurait pourtant accepté que vous fussiez… ce
que beaucoup d’autres femmes avaient été pour lui avant qu’il vous
rencontrât ?
— Il a compris très vite qu’il devait y renoncer. Et quand il s’est
décidé pour le mariage, il a mis une obstination extrême à me
décider au divorce… J’ai résisté… tant que j’ai pu…
— Par sentiment religieux ?
Elle fit signe que oui, sans parler.
— Vous n’avez pas songé à vous adresser à Rome pour obtenir
l’annulation de votre premier mariage ?
— Paul… (elle se reprit) le prince s’y opposait. Il ne voulait pas
attendre… On dit que les délais sont si longs.
Comme elle prononçait ces mots, Stéphanie sentit que le regard
du Père, immobile sur elle, lisait dans sa conscience. Elle n’osa pas
achever.
— Oui, murmura le Père. C’est bien l’homme qu’on m’a dépeint. Il
voulait sur vous la victoire complète… l’abjuration. Une sorte de
Polyeucte satanique. Vous avez cédé… vous avez divorcé… Et sous
quel régime avez-vous épousé le prince Paul ?
— Mais… civilement d’abord, selon la loi du pays. Et
religieusement ensuite selon le rite orthodoxe.
Une pause. Puis :
— Quelle a été l’attitude, vis-à-vis de vous, de la famille royale ?
— De la résistance d’abord, naturellement. Mais, comme l’opinion
publique était favorable à notre mariage, — le prince est très aimé
du peuple, — et aussi, parce que… son amitié pour moi d’abord, le
mariage ensuite parurent tellement l’assagir… le roi et la reine m’ont
assez vite adoptée. Je n’ai eu guère contre moi, à la cour, que la
princesse Marie, la tante de Paul, qui est fort bizarre, son cousin
Charles-Henri, qui le déteste.
Le silence régna quelque temps entre les murs vert pâle de la
pièce. Stéphanie ne quittait pas le Père des yeux : elle éprouvait un
soulagement à lui parler, et si pénible que fussent pour elle les
souvenirs qu’il faisait revivre, elle souhaitait qu’il l’interrogeât de
nouveau. Or, en ce moment, l’esprit du moine semblait absent, et
l’on eût dit qu’il avait oublié la retraitante. Il regardait du côté de la
fenêtre. Des nuages traversaient le carré de ciel bleuâtre, des
nuages blancs et gris, qui par intervalles masquaient le soleil. La
cime déjà rousse d’un marronnier oscillait sous des poussées de
brise. Le Père observait tranquillement cela, en tapotant des deux
mains le rebord de son bureau. Et Stéphanie en profitait pour
incorporer à sa mémoire ce masque triangulaire, ce crâne tondu de
si près que la tonsure ecclésiastique s’y distinguait à peine, cette
figure bourgeonnée et pourtant austère, avec la bouche forte des
portraits du X V I e siècle, ce nez étrange, ce nez puissant en forme de
gouvernail, un peu obliqué vers la droite. Stéphanie osait regarder
parce que les yeux arrondis, les yeux d’oiseau du Père étaient en ce
moment détournés. Dès qu’il les ramena sur elle, elle abaissa les
siens.
— Alors… le prince a changé de conduite aussitôt après vous
avoir épousée ? dit le prêtre, comme s’il n’avait pas interrompu
l’interrogatoire.
— Oui, mon Père.
— Il vous a été fidèle ?
Elle hésita.
— Je le crois… Je l’ai cru fermement en ce temps-là… Maintenant
que j’ai appris à le connaître, je ne suis pas sûre… Il est si habile à
dissimuler sa pensée et à cacher ses actions, quand il veut ! mais,
durant plusieurs mois, nous avons voyagé tête à tête en Italie. Nous
ne nous quittions pas un instant… comme deux étudiants,
incognito… sans femme de chambre, sans valet de chambre… sans
même l’affreux Osterrek.
— Qui est Osterrek ?
— Un camarade d’enfance et d’études, avec qui le prince a suivi
jadis des cours à la Faculté de Paris, et qui est devenu son âme
damnée, son… (elle hésita devant le mot qui lui venait) son agent
auprès des femmes. Osterrek avait été le premier intermédiaire
entre Paul et moi… Il avait tout aplani pour le divorce et le mariage,
car il a une adresse et une énergie infernales. Mais mon instinct me
le révélait dangereux, et j’avais exigé qu’il ne nous accompagnât
point. Je me rendais compte que…
— Vous avez été heureuse pendant ce voyage nuptial ?
interrompit sèchement le Père.
Et sa voix de nouveau se timbrait d’ironie, comme tout à l’heure,
quand il avait dit à Stéphanie, à propos du départ de Paul : « Cela
vous émeut ? »
Un moment interloquée, elle fit un effort pour répondre :
— J’ai été heureuse… Oh ! je sais bien que je n’en avais pas le
droit… et j’ai payé cher ce bonheur-là. Mais il s’est appliqué à me
rendre heureuse avec cette volonté fervente, cette mise en œuvre
de tout son esprit, de toute sa science de la femme, de sa grâce
naturelle et de l’artifice dont il sait jouer. Que je fusse enivrée de
bonheur, c’était son objet sans répit, et cent fois au cours de ce
voyage il m’a demandé si je ne regrettais rien, si je recommencerais.
— Oui, grommela le prêtre. Je comprends. Son génie diabolique,
qui avait renoncé à vaincre votre pudeur de femme, s’excitait à l’idée
qu’il avait piétiné votre foi religieuse. Comme ces pirates arabes qui
forçaient les chrétiennes captives à souiller le Crucifix. Et cela vous a
donné du bonheur ?… Pauvre enfant !
Il prit un instant sa tête entre ses mains, appuyant ses coudes à
son bureau ; et de voir soudain accablé cet homme robuste et dur,
Stéphanie fut bouleversée jusqu’au fond des entrailles. « Il a raison,
pensait-elle. C’est bien cette victoire sacrilège sur ma conscience que
Paul a souhaitée. Je n’ai jamais osé le comprendre… Et voilà que ce
prêtre le découvre à première vue, et me le révèle. »
Enfin le Père Orban démasqua et releva son visage, qui restait
préoccupé, triste.
— Combien de temps a duré ce parfait bonheur ?
— Plus d’une année, murmura Stéphanie.
Mais quelque chose l’oppressait, qu’elle ne trouvait pas le moyen
de dire, et qu’elle aurait voulu dire. La question que le Père lui posa
fut exactement la réplique à ce scrupule :
— Un bonheur… sans remords ?
— Oh ! non, mon Père. J’avais des moments douloureux, mais
j’étais grisée, possédée.
— Et vos remords étaient seulement causés parce que vous aviez
rompu des liens que Dieu seul peut rompre ?
Elle fut sincère en montrant, d’abord, qu’elle ne comprenait pas
la question. Mais le regard fixe du prêtre continuait à la parcourir, à
la pénétrer… Elle se cacha le visage et ne répondit pas. Ainsi isolée
en face de sa conscience subitement béante devant elle comme un
puits qu’on découvre, elle entendit que le Père se levait, qu’il allait à
la fenêtre, qu’il l’entr’ouvrait. Elle sentit une fraîcheur de vent un peu
humide circuler autour de ses joues et de ses cheveux. Dans la cour
aux marronniers, un campanile de zinc jeta une à une les bulles
sonores dont l’addition faisait onze heures. Stéphanie revit sur le
transparent pourpre de ses mains, interposées entre elle et le jour, le
paysage ras aperçu au déclin du soleil, la verdure du parc, le faîte
des six dômes d’ardoise, l’angle de la route et de l’allée. Alors aussi,
elle avait entendu le grêle campanile ébruiter dans la solitude la
confidence de l’heure… Qu’ils lui avaient paru douloureux, quasi
menaçants, ces coups successifs qu’elle imagina prisonniers, comme
tout ce qui habitait le monastère, comme elle-même allait être tout à
l’heure ! Cette impression n’était pas vieille de quatre jours, et voilà
qu’en ce moment, meurtrie pourtant par quelques mots d’une
bouche sévère, elle aimait cette sonorité cloîtrée, cette heure
dispensée pour elle et pour ses compagnes de solitude.
« Faites que je ne rêve pas, mon Dieu ! pensa-t-elle… et que cela
dure !… »
Plus d’une minute certainement, le Père Orban demeura devant
la fenêtre ouverte, qu’il obstruait de sa haute et lourde stature noire.
« Il prie », pensa la retraitante, et elle essaya vainement d’unir une
prière à la sienne. Son cœur fut sec et désert ; elle n’était qu’anxiété,
désir de connaître ce qui allait se passer tout à l’heure, ce qu’on
allait faire d’elle. Quand le prêtre, ayant refermé la fenêtre, revint
vers son fauteuil, elle remarqua un sensible adoucissement de ses
traits, quelque chose de pitoyable dans les yeux, qui en était absent
au cours de leur entretien. Il lui dit, debout devant elle qui n’osait
pas se lever :
— Ma chère enfant, vous allez retourner dans votre chambre,
pour méditer et pour prier, si vous pouvez prier. Si vous ne pouvez
pas prier, ce qui n’aurait rien d’étonnant, parce que vos nerfs sont en
ce moment surtendus, contentez-vous de méditer sur notre
conversation d’aujourd’hui. Méditez même la plume en main, si vous
sentez que votre esprit se dérobe et veut divaguer… Méditez sur les
questions que je vous ai posées et sur les réponses que vous avez
faites. Si décidément vous ne pouvez même pas méditer, lisez
l’histoire de l’ordre de la Sainte-Quarantaine que je vais faire mettre
à votre disposition. Ne craignez pas de vous distraire en observant
les choses nouvelles qui sont autour de vous, les coutumes, les
personnes même. Très vite, je vous en préviens, tout cela ne
comptera plus pour vous. N’anticipez pas : vous êtes à peine sortie
du monde. On vous a confiée à un guide exceptionnel, malgré sa
jeunesse. Madeleine de Sainte-Madeleine n’est ici que ce que l’on
appelle dans le monde une apprentie, et que nous appelons, nous,
une postulante. La courte histoire de sa vie (elle n’a pas vingt-deux
ans) semble porter la marque d’une sainte prédestination. Orpheline,
recueillie par une institution de sauvetage pour l’enfance, elle est
placée vers sa douzième année dans une ferme des environs : or il
se trouve que cette ferme est un cloaque immonde, quelque chose
comme la maison Bancal dans le drame de Fualdès. Elle y assiste à
des spectacles affreux, passe à travers cette boue sans souiller sa
robe et à travers ce feu sans se brûler, jusqu’au jour où elle n’a plus
d’autre recours que de s’échapper et de nous demander asile… Elle
était épuisée : on la soigne. Nous obtenons de la garder. Elle aide
nos sœurs converses, puis devient infirmière : cependant son
développement intellectuel et religieux est si rapide, si surprenant,
que nous l’affectons au service des retraitantes. Son intelligence
aiguë est servie par une mémoire prodigieuse. Tout ce qui l’a
intéressée s’y inscrit de façon indélébile… Elle sait par cœur tous les
offices et des passages entiers des grands mystiques. Il ne tiendrait
qu’à elle d’être novice, demain, et de faire bientôt sa profession…
Elle dit, — elle me dit — que sa sainte patronne, pour laquelle elle
professe une édifiante dévotion, lui conseille d’attendre. Je n’insiste
pas : elle me paraît être de ces âmes choisies qui communiquent
directement avec la Vérité… Elle sait tout ce qu’elle n’a jamais
appris. Elle voit tout ce que nous cherchons vainement à deviner, à
pressentir. Et avec cela, l’humilité et la simplicité même, et
j’ajouterai, la gaîté même. J’imagine que sainte Jeanne d’Arc, enfant,
devait être ainsi. Confiez-vous à elle, ce qui vous sera peut-être plus
facile que de vous confier à moi. Écoutez ce qu’elle vous répondra.
J’estime son jugement pour la consulter parfois sur des choses
graves et difficiles…
Il reprit sa place dans son fauteuil, mais le tourna vers Stéphanie
et se pencha vers elle, avec une familiarité paternelle qui la rassura :
— Je vous entendrai en confession, ma chère fille… non pas
demain… mais après-demain mercredi, fête de la bienheureuse qui
est une de nos fondatrices. Préparez-vous à cet acte essentiel. Si
votre esprit ne se fixe pas aisément, ce qui est fréquent quand on
vient au cloître directement de la dissipation du monde, prenez une
plume (j’y insiste) et écrivez votre confession. Vous pourrez me la
lire… ou me la dire de mémoire, comme vous l’aimerez mieux. Mais
que ce soit un inventaire bien définitif, sur lequel il n’y ait plus à
revenir. De là, nous partirons vers le rétablissement de votre âme et,
si Dieu le permet, vers une vie morale nouvelle. C’est compris ?
— Oui, mon Père.
— Je ne compte pas avoir d’entretien avec vous jusqu’à jeudi
matin, au confessionnal, après ma messe. D’ici là, vous êtes livrée à
vous-même, sous la conduite de Madeleine de Sainte-Madeleine…
Suivez strictement son inspiration au point de vue des offices, des
repos, des méditations, des prières, des récréations. Ici, la règle des
retraitantes est d’une souplesse infinie. Elles sont si diverses par
l’origine, par l’esprit, par leur passé ; comment les plier utilement et
du premier coup à une discipline identique ? Nous avons des
retraitantes dont la vie ne ressemble en rien à celle des moniales,
qui n’interrompent point leurs relations avec leur famille, qui ne font
pas de pénitence sévère, qui vivent parmi nous, purement,
paisiblement, sans plus. Nous en avons aussi qui font l’exemple et
l’édification des moniales elles-mêmes… Suivez les inspirations de la
pure jeune fille qui doit vous guider, et allez en paix.
Stéphanie se leva : puis, levée, elle hésita. Elle aurait voulu
parler, mais elle ne sentait absolument aucune idée solliciter
l’expression des paroles. Et pourtant, il lui en coûtait de quitter le
Père Orban, tant elle sentait l’envie de se libérer tout de suite des
secrets qui opprimaient sa conscience.
Mais le Père répéta avec une ferme douceur :
— Allez en paix !
Elle obéit.
IV

Une stupeur paralysa Stéphanie en sortant de son entretien avec


le Père Orban… Oui, stupeur : rien de net dans la pensée ; dans le
vouloir, rien de ferme. Passé le seuil, la porte refermée derrière elle,
elle se sentit hors du champ d’influence dont elle avait subi l’action,
tout le temps de l’audience : comme le patient soumis à des rayons
ultra-violets, lorsque le médecin fait stopper l’appareil. Refoulé par le
refus, le besoin de se confier, d’avouer, si violent lors de leurs
dernières répliques, l’oppressait et l’irritait.
« Décidément, on ne veut pas de moi… Et ce prêtre qui me dit
d’aller en paix ! Formules creuses que tout cela ! »
A l’angle du corridor qu’elle suivait comme une somnambule,
sans trop savoir si vraiment elle regagnait sa chambre, une ombre se
projeta : Stéphanie devina Madeleine. La jeune fille parut, un peu
essoufflée :
— J’ai couru… La Sœur Incarnation m’avait mandée, et elle m’a
retenue. Mais je ne vous quitte plus.
Stéphanie ne répondit rien. Madeleine ayant mis, de son geste
familier, deux doigts sur l’avant-bras, elle obéit machinalement et
suivit. Toutes les deux se trouvèrent bientôt dans la chapelle des
« passages », complètement déserte à cette heure-là, mais cette fois
à genoux au premier rang, sur l’agenouilloir de la grande stalle, où
nulle séparation ne marquait les places. Le tableau de la Descente
de Croix occupait ainsi tout le champ visuel : la verrière ronde qui
perçait le mur de gauche l’éclairait fortement, avec un reflet plus
éclatant sur la face du Sauveur et son buste à l’entaille sanglante.
Les deux femmes étaient si près l’une de l’autre que Stéphanie sentit
les lourds plis laineux et noirs de la jupe de Madeleine frôler sa
propre jupe, si légère : ce fut une impression de chaleur vivante,
qui, de sa jambe ployée, se répandit dans tout son corps. Influx de
vie et pourtant rien de charnel ; rien de certains contacts suspects
cherchés et goûtés naguère ; quelque chose de dominateur aussi, et
pareillement d’entraînant, d’activant, mais qui, loin d’accélérer et de
faire vibrer les sens, sublimait la sensibilité, diminuait l’animalité du
composé humain… En cet instant, il y eut en elle une réaction du
moi instinctif comme en ont les patients qu’on éthérise : ils
disputent, dans un spasme impuissant, leur conscience à
l’anéantissement. Une communication de sensibilité s’établit entre
les deux corps agenouillés. Communication subtile et vague, mais
plus efficace que par les mots… Stéphanie dut regarder ce que
regardait Madeleine, dont le visage n’avait plus exactement l’air
d’extase de l’avant-veille, mais une admirable expression implorante.
Ainsi la pécheresse et la vierge, mêlant dans un pur contact la
chaleur matérielle de leurs corps, sentirent leur pensée, leur désir,
tout l’immatériel de leurs deux êtres, se rejoindre, portés par leurs
regards sur la plaie béante qui agonisait devant elles. Cela encore ne
s’accomplit point sans résistance de la part de Stéphanie ; elle eut
des velléités de se soustraire ; des éclairs de lucidité lui laissèrent
percevoir des lambeaux de réflexions hostiles : « Rien d’étonnant…
Je suis une proie trop facile… Lui aussi, quand il voulait, rien qu’en
appuyant sa main sur mon front… » Mais bientôt elle ne pensa plus,
elle ne voulut plus rien. Priait-elle ? Non : la voix silencieuse qui
articule en nous, pour nous seuls, les mots de nos pensées s’était
comme atrophiée. Stéphanie ne sollicitait rien. Elle n’avait pas de
souhait. Mais elle ne souffrait plus. Elle était emportée (ascension
éperdue ou descente vertigineuse), si vite que cela dépassait les
catégories de la perception des sens. Nulle appréhension. Elle ne
demandait pas que cela finît. Son regard seul vivait en elle, pour
s’unir à celui de Madeleine sur la blessure toujours vivante au flanc
du Crucifié.
Elle ne récupéra la pleine conscience des choses que lorsqu’elle
se retrouva dans sa chambre, avec Madeleine toujours. Le repas de
midi était préparé dans un plateau sur la table.
— Oh ! Madeleine, fit-elle, je ne suis pas capable d’avaler un
morceau de pain.
Sans résister et sans même répondre, la postulante emporta le
plateau.
— Je reviens dans une minute, dit-elle.
Elle la retrouva assise à la même place, immobile. Elle s’assit en
face d’elle.
— Nous avons prié près d’une heure, fit-elle. Maintenant nous
comprendrons ce qu’il faut faire.
— Je n’ai pas prié, objecta Stéphanie.
— Vous le croyez. Vous vous rendrez compte tout à l’heure que
vous avez prié…
« Je me sens un peu hébétée, voilà tout, pensa la comtesse… Et
c’est une sensation qui ne m’est pas nouvelle non plus. S’échapper
de soi-même, ne plus penser, ne plus vouloir… cela ne manque pas
de charme. Mais cela se paye, après ! »
Avait-elle dit cela tout haut, sans s’en rendre compte ? Dans l’état
où elle était, ce n’était pas impossible. Le certain, c’est que la
réponse de Madeleine s’adapta exactement, une fois de plus :
— Non ! vous n’avez rien à craindre. La prière, comme nous
l’avons faite, ne vous brise pas, au contraire. Vous verrez !
Mais Stéphanie, en reprenant possession d’elle-même, se sentait
nerveuse et hostile.
— Pour le moment, fit-elle, je n’ai qu’une envie : dormir.
Madeleine ne répondit pas : un flux de tristesse se répandit sur
son visage, et ses paupières se gonflèrent de larmes. Mais déjà
Stéphanie s’était jetée contre elle et la serrait contre son cœur en
balbutiant :
— Pardon !… je ne vaux rien. Je mériterais qu’on me prive de toi
et qu’on me jette hors d’ici… Ne me repousse pas. Ne m’abandonne
pas… Aide-moi, défends-moi !…
Cet élan, ni le tutoiement ne troublèrent point la jeune fille. Au
contraire, comme il advient souvent en présence de la crise
d’émotion d’autrui, elle réagit, cessa de pleurer. Un moment, elle
laissa Stéphanie s’appuyer contre elle, puis elle se désenlaça
doucement.
— Asseyons-nous, dit-elle.
Et, quand elles furent assises, Stéphanie encore toute vibrante,
et Madeleine opposant à ce désarroi un calme plein de naturel :
— Est-ce que le Père Orban vous entendra bientôt en confession ?
— Après-demain… Je dois me préparer d’ici là.
— Alors ?… Je crois qu’il vaut mieux commencer le plus tôt
possible.
L’exaltation nerveuse de Stéphanie se ranima :
— Commencer ?… Commencer quoi ? On ne vous a donc rien dit ?
Vous ne savez donc pas ce que je suis ?
— On m’a dit votre nom… Je ne l’ai pas retenu…
— C’est cela… Vous ne connaissez même pas mon nom. Et vous
ne savez pas…
Et lui prenant les mains, qu’elle serra à les meurtrir, et
recommençant le tutoiement qui venait de lui-même à ses lèvres de
grande dame :
— Tu ne sais pas que je ne me suis pas confessée depuis plus de
deux années ?… que si je m’étais confessée, aucun prêtre n’aurait pu
m’absoudre, et que j’ignore si le Père Orban le pourra lui-même ? Je
suis hors de l’Église, entends-tu ? Hors de la communion des fidèles.
Je suis mariée à un homme, et voilà deux années que je vis avec un
autre.
— Jésus, dit la jeune fille, n’a pas dédaigné la Samaritaine, et
pourtant il lui a dit : « Tu as eu cinq hommes, et celui que tu as en
ce moment n’est pas ton mari… »
Il y avait tant de sérénité dans la réponse de Madeleine que
Stéphanie comprit alors ce qu’avait dit d’elle le Père Orban :
« Elle traverse la boue sans tacher sa robe et le feu sans se
brûler. »
— Moi, murmura-t-elle, comme pour elle-même, j’ai trop souillé
ma robe… Vois-tu, reprit-elle, s’adressant à Madeleine, j’ai honte
d’être ici. Ma présence auprès de toi me fait honte.
Son exaltation s’activait, elle parlait, parlait, comme affranchie du
contrôle de toute convenance, et de sa propre volonté :
— Ce n’est pas ma faute, peut-être ! Je n’étais pas née pour
aboutir à cette pourriture. Je ne demandais qu’à être une femme
mariée honnête, à avoir des enfants, à vivre… platement, comme
une petite bourgeoise, dans ma province.
Elle sanglotait à présent, retournée à une sorte de puérilité
soignante. Madeleine l’observait, sans l’interrompre, avec des yeux
attentifs qui ne marquaient aucun étonnement.
— Non… Ce n’est pas ma faute, reprit la pécheresse avec des
hoquets de sanglots, des gestes convulsifs de tous ses membres et
une insouciance affreuse de son désordre et de son humiliation.
J’avais horreur de toutes les bassesses. Surtout de celles qui font
des hommes et des femmes pire que les animaux immondes… Moins
sainte que toi, Madeleine, mais pure à ta manière… Oui ! le Père
Orban m’a dit sur toi… je sais, je sais. Pure par nature, par dégoût…
Sans tentation… sans mérite… Et si un certain homme, un seul,
n’avait pas été mis sur mon chemin… je suis sûre que je serais
encore pareille à toi.
Elle s’arrêta, égarée dans sa propre pensée. Elle s’essuya les
yeux, se moucha, leva vers Madeleine une face ravagée, pathétique,
dont toute beauté désirable avait disparu et sur laquelle —
apparition tragique — à travers les beaux traits conservés jusque-là
par les soins et par l’amour, se projeta soudain l’ombre de la
vieillesse. Elle pleurait, sans relâche. Ce fut Madeleine qui
interrogea :
— Cet homme… c’est celui qui vous a enlevée à votre mari ?
— Il est mon mari devant la loi de son pays… J’ai divorcé.
— Ah !
Elle ne dit rien de plus. Elle semblait se recueillir et méditer… La
retraitante que l’explosion des pleurs avait un peu calmée, et qui ne
sanglotait plus, approcha sa chaise de celle de la novice, s’assit tout
contre elle, cherchant instinctivement, dans sa détresse, cette
chaleur humaine qui l’avait engourdie tout à l’heure, devant l’autel.
Madeleine ne se déroba point : elle restait pensive.
— Mais pourquoi, demanda-t-elle, avez-vous suivi cet homme,
puisque les créatures vous étaient indifférentes… comme à moi ?
— Je l’ai aimé.
Pour la première fois depuis les trois jours qu’elle vivait à son
côté, Stéphanie perçut une palpitation sur le calme visage de la
jeune fille. Ce ne fut qu’un instant, comme ces éclairs d’été, à
l’extrême horizon, dont on ne sait, l’instant d’après, s’ils ne furent
pas une contraction intérieure de nos yeux.
— Tu n’as pas l’air de me comprendre, reprit Stéphanie,
qu’animait un irrésistible besoin de parler enfin de son passé et du
Maître de ce passé. Je l’aimais. Cela dit tout.
Avec cette minutieuse lenteur de parole, où se marquait l’effort
de la réflexion, Madeleine répondit :
— Aimer, c’est vouloir le bien pour ce qu’on aime.
— De toutes mes forces, j’ai voulu le rendre heureux.
— Mais vous… puisqu’il vous a rendue malheureuse, il ne vous
aimait pas ?
— Si, il m’aimait… Ah ! vois-tu, Madeleine (aucune des deux ne
s’aperçut, à cette heure climatique, qu’elles échangeaient leur rôle),
ce sont des choses que tu ne peux pas comprendre. Heureusement
pour toi… Je te dis que je sais… le Père Orban m’a dit ton enfance,
tes épreuves. Tu as vu, tu as entendu ces brutes humaines pour qui
l’amour est de l’ordre de la gloutonnerie ou de la boisson… De cela,
je me serais sauvée comme tu t’es sauvée, empoisonnée de dégoût.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like