An Introduction to Object-Oriented Programming with

Similar documents
Computing Concepts with Java Essentials

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Direct Marketing AN INTEGRATED APPROACH

Fundamentals of Java Programming

Java the UML Way: Integrating Object-Oriented Design and Programming

Enterprise Java. Where, How, When (and When Not) to Apply Java in Client/Server Business Environments. Jeffrey Savit Sean Wilcox Bhuvana Jayaraman

Programming and Software Development CTAG Alignments

Java Application Developer Certificate Program Competencies

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Software Project Management (Second Edition)

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

El Dorado Union High School District Educational Services

Java (12 Weeks) Introduction to Java Programming Language

Curriculum Map. Discipline: Computer Science Course: C++

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

NEW ZEALAND FINANCIAL ACCOUNTING

Compensating the Sales Force

Numerical Methods for Engineers

Financial Statement Analysis

Fundamentals of THERMAL-FLUID SCIENCES

Syllabus for CS 134 Java Programming

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

Oracle JDeveloper 10g for Forms & PL/SQL

Designing Interactive Systems

NEW YORK CITY COLLEGE OF TECHNOLOGY/CUNY Computer Systems Technology Department

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Ninth Edition. David W. Cravens. Nigel F. Piercy. McGraw-frSiBI irwin. M.j. Neeley School of Business Texas Christian University

How To Understand The Software Development Lifecycle

Distinguished Professor George Washington University. Graw Hill

Some programming experience in a high-level structured programming language is recommended.

THE OPEN UNIVERSITY OF TANZANIA

Computer Organization

Basic Programming and PC Skills: Basic Programming and PC Skills:

Fundamentals of Programming and Software Development Lesson Objectives

Web Development in Java

Lewis, Loftus, and Cocking. Java Software Solutions for AP Computer Science 3rd Edition. Boston, Mass. Addison-Wesley, 2011.

Domains and Competencies

OPERATIONS MANAGEMENT

James Dicks. 6 Ways to Trade the Dollar. McGraw-Hill

Programming and Software Development (PSD)

Performance Management

Manager's Guide to Crisis Management

for Hundreds of Ready-to-Use Phrases to Set the Stage for Productive Conversations, Meetings, and Events Meryl Runion with Diane Windingland

Winning the Hardware-Software Game

Implementation & Administration

QUANTITATIVE METHODS. for Decision Makers. Mik Wisniewski. Fifth Edition. FT Prentice Hall

Tuning Tips & Techniques

Oracle8/ SQLJ Programming

Manager's Guide to Performance Management

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Macroeconomics. Manfred Gartner. Prentice Hall THIRD EDITION. University of St Gallen, Switzerland. An imprint of Pearson Education

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

BIRT: A Field Guide to Reporting

Computer Science III Advanced Placement G/T [AP Computer Science A] Syllabus

TYLER JUNIOR COLLEGE School of Continuing Studies 1530 SSW Loop 323 Tyler, TX

Sixth Edition. Steven M. Glover Brigham Young University Marriott School of Management School of Accountancy

Lean Supply Chain and Logistics Management

Programming Language Pragmatics

Oracle Backup & Recovery

Public Relations in Schools

Relationship marketing

VISUALIZING DATA POWER VIEW. with MICROSOFT. Brian Larson. Mark Davis Dan English Paui Purington. Mc Grauu. Sydney Toronto

THE PSYCHOLOGY OF INVESTING

BUSINESS AND PROFESSIONAL COMMUNICATION

FLORIDA STATE COLLEGE AT JACKSONVILLE COLLEGE CREDIT COURSE OUTLINE. Introduction to Programming with Visual Basic.NET

Chapter 6: Programming Languages

NEURAL NETWORK FUNDAMENTALS WITH GRAPHS, ALGORITHMS, AND APPLICATIONS

Morris School District. AP Computer Science A Curriculum Grades 9-12

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

SCHOOL FINANCE. A Policy Perspective. ALLAN R. ODDEN University of Wisconsin-Madison SECOND EDITION. University of Southern California

AP Computer Science Java Subset

Building and Managing

Java Software Structures

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

How To Write A Diagram

EMC Publishing. Ontario Curriculum Computer and Information Science Grade 11

Course Title: Software Development

Visual Basic. murach's TRAINING & REFERENCE

Computer Programming I

Android Application Development Course Program

How to Implement Lean Manufacturing

Business Finance. Theory and Practica. Eddie McLaney PEARSON

C# Cookbook. Stephen Teilhet andjay Hilyard. O'REILLY 8 Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo '"J""'

The Data Access Handbook

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

Lecture 1: Introduction

Security Metrics. A Beginner's Guide. Caroline Wong. Mc Graw Hill. Singapore Sydney Toronto. Lisbon London Madrid Mexico City Milan New Delhi San Juan

Specialized Programme on Web Application Development using Open Source Tools

Study Guide. Professional vsphere 4. VCP VMware Certified. (ExamVCP4IO) Robert Schmidt. IVIC GratAf Hill

Transcription:

An Introduction to Object-Oriented Programming with TM Java C. Thomas Wu Naval Postgraduate School Ml McGraw-Hill Boston Burr Ridge, IL Dubuque, IA Madison, WI New York San Francisco St. Louis Bangkok Bogota Caracas Lisbon London Madrid Mexico City Milan New Delhi Seoul Singapore Sydney Taipei Toronto

Preface Major Features xiv Supplement Materials xxii Book Organization xxiv Acknowledgments xxvi xiii Introduction to Computers and Programming Languages 1 0.1 A History of Computers 2 0.2 Computer Architecture 5 0.3 Programming Languages 11 0.4 Java 13 0.5 Exercises 14 Introduction to Object-Oriented Programming and Software Development 15 1.1 Classes and Objects 16 1.2 Messages and Methods 19 1.3 Class and Instance Data Values 24 1.4 Inheritance 27 1.5 Software Engineering and Software Life Cycle 30 1.6 Having Fun with Java 32 1.7 Exercises 35

Java Programming Basics 2.1 The First Java Application 40 2.2 Program Components 49 2.3 Edit-Compile-Run Cycle 59 2.4 The javabook Package 62 2.5 Sample Program: Displaying Messages 63 2.6 The First Java Applet 68 2.7 Exercises 78 Numerical Data 3.1 Variables 84 3.2 Arithmetic Expressions 92 3.3 Constants 98 3.4 The Math Class 100 3.5 InputBox 103 3.6 OutputBox 106 3.7 Sample Program: Loan Calculator 113 3.8 Numerical Representation (Optional) 125 3.9 Exercises 129 Defining Instantiable Classes 4.1 Defining Instantiable Classes 142 4.2 Instantiable Classes and Constructors 154 4.3 Visibility Modifiers: public and private 159 4.4 Local Variables, Return Values, and Parameter Passing 164 4.5 Loan Calculator Program with an Instantiable Class 170 4.6 Exercises 185

ix Processing Input with Applets 195 5.1 Placing GUI Objects on Applets 196 5.2 Adding an Action Listener to an Event Source 204 5.3 Absolute Positioning of GUI Objects 211 5.4 The Button Class 212 5.5 Converting Text to a Numerical Value 215 5.6 Sample Program: Finding Body Mass Index (BMI) 218 5.7 Running an Applet as an Application 229 5.8 Exercises 230 Selection Statements 235 6.1 The if Statement 236 6.2 Boolean Expressions and Variables 244 6.3 Nested-if Statements 249 6.4 ListBox 256 6.5 The switch Statement 260 6.6 Sample Program: Drawing Shapes 266 6.7 Exercises 289 Repetition Statements 297 7.1 The while Statement 298 7.2 Pitfalls in Writing Repetition Statements 302 7.3 The do-while Statement 307 7.4 ResponseBox 312 7.5 The for Statement 317 7.6 Nested for Statements 322 7.7 The Format Class 325 7.8 Loan Tables 332 7.9 Sample Program: Hi-Lo Game 335

X Contents 7.10 (Optional) Recursive Methods 349 7.11 Exercises 353 Characters and Strings 365 8.1 Characters 366 8.2 Strings 369 8.3 Primitive versus Reference Types 381 8.4 StringBuffer 389 8.5 Passing Objects as Parameters 396 8.6 Returning an Object from Methods 401 8.7 Sample Program: Word Play 404 8.8 Exercises 417 Arrays 9.1 y.z 9.3 9.4 9.5 9.6 9.7 9.8 Array Basics 426 Arrays of Objects 435 Passing Arrays to Methods 446 MultilnputBox 452 Self-Referencing Pointer 455 Sample Development: The Address Book 462 Two-Dimensional Arrays 480 Exercises 488 425 File Input and Output 493 10.1 File and FileDialog Objects 494 10.2 Low-Level File I/O 500 10.3 High-Level File I/O 506 10.4 Handling Exceptions 513 10.5 Object I/O 519

10.6 Sample Class: Saving an AddressBook Object 522 10.7 Exercises 531 Reusable Classes and Packages 535 11.1 Object Categories 536 11.2 Method Overriding and Overloaded Methods 538 11.3 Sample Classes: Reusable EggyPeggy and HiLo 545 11.4 Package Organization 572 11.5 Exercises 575 GUI Objects and Event-Driven Programming 581 12.1 Placing Buttons on a Frame 583 12.2 Handling Events 589 12.3 Placing TextField Objects on a Frame 596 12.4 Menus 598 12.5 Handling Mouse Events 605 12.6 Other GUI Objects 615 12.7 Sample Program: A Simple Calculator 620 12.8 Exercises 633 Inheritance and Polymorphism 639 13.1 Defining Classes with Inheritance 640 13.2 Using Classes Effectively with Polymorphism 645 13.3 Inheritance and Member Accessibility 648 13.4 Inheritance and Constructor 654 13.5 Abstract Superclasses and Abstract Methods 659 13.6 When and When Not to Use Inheritance 665 13.7 Sample Program: Computing Course Grades 667 13.8 Exercises 689

XII Contents Class Roster Maintenance Program 695 14.1 Method Call Sequence Diagram 696 14.2 Problem Statement 697 14.3 Overall Planning 698 14.4 Step 1 Development: Program Shell with Menus 701 14.5 Step 2 Development: Create a New Roster 708 14.6 Step 3 Development: Add Students 716 14.7 Step 4 Development: Delete Students 724 14.8 Step 5 Development: Edit Student Names 728 14.9 Step 6 Development: Edit Test Scores and Compute Grades 734 14.10 Step 7 Development: Display Student Information 741 14.11 Step 8 Development: Storing Grade Rosters 754 14.12 Step 9 Development: Finalize and Improve 764 14.13 The StudentNameDialog Class 765 14.14 The TestScoreDialog Class 775 14.15 Exercises 780 Searching, Sorting, and Recursive Algorithms 785 15.1 Searching 786 15.2 Sorting 792 15.3 Recursion 800 15.4 When Not to Use Recursion 817 15.5 Exercises 819 The javabook Package 823