© 2006 Pearson Addison-Wesley. All rights reserved 3.2.1 Design by Prototype Programmers often approach a problem by creating a series of prototypes. Each.

Slides:



Advertisements
Similar presentations
Chapter 15 Debugging. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Debugging with High Level Languages.
Advertisements

Chapter 6 Modular Programming J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 1: Introduction
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
Program Flow Charting How to tackle the beginning stage a program design.
Chapter 2: Input, Processing, and Output
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
PRE-PROGRAMMING PHASE
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Programming and Visual Basic.
Object-Oriented Programming in Java. Object-Oriented Programming Objects are the basic building blocks in an O-O program. – A program consists of one.
Programming Languages: Telling the Computers What to Do Chapter 16.
1 Using Classes Object-Oriented Programming Using C++ Second Edition 5.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Using Classes Object-Oriented Programming Using C++ Second Edition 5.
CSE 1340 Introduction to Computing Concepts Class 2.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
The Java Programming Language
CMPE13Cyrus Bazeghi 1 Programming Languages Telling computers what to do.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 13 Programming in the Large Dr. Jiung-yao Huang Dept. Comm. Eng. Nat. Chung Cheng Univ. TA: 鄭筱親 陳昱豪.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
Java Graphics Graphical Components as objects. Graphics A Component is ◦A rectangular region of a computer screen ◦A graphical entity ◦Can sometimes contains.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Copyright © 2011 Pearson Addison-Wesley What is a Program Made Of? Keywords (Reserved Words) – Words with special meaning that make up a high-level programming.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
How to Program? -- Part 1 Part 1: Problem Solving –Analyze a problem –Decide what steps need to be taken to solve it. –Take into consideration any special.
4.3.1 Non-void Methods Parameters are largely one-way communication.  Shared instances variables is one way to accomplish this. calling codemethod parameter.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Lecture 3.1 Using Graphics with JFrame. © 2006 Pearson Addison-Wesley. All rights reserved javax.swing.JFrame - int x - int y - int width - int.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
© 2006 Pearson Addison-Wesley. All rights reserved Non-void Methods Parameters are largely one-way communication.  Shared instances variables is.
CMSC 202 Polymorphism. 10/20102 Topics Binding (early and late) Upcasting and downcasting Extensibility The final modifier with  methods  classes.
CMSC 2021 Software Development. CMSC 2022 Software Development Life Cycle Five phases: –Analysis –Design –Implementation –Testing –Maintenance.
Lecture 4.1 More About Methods - Using a Prototyping Approach.
Chapter 3 Part II. 3.8 Placing a Class in a Separate File for Reusability.cpp file is known as a source-code file. Header files ◦ Separate files in which.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
Lecture 1 Introduction. © 2006 Pearson Addison-Wesley. All rights reserved 1-2 Your world is filled with objects. Many of these objects are controlled.
Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into.
Principles of Programming & Software Engineering
Wrapper Classes Debugging Interlude 1
Prototyping with Methods
John Woodward A Simple Program – Hello world
Loop Structures.
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Prototyping with Methods
1.7 Errors Compile-time error: A violation of the programming language rules that is detected by the compiler Example: System.ou.println("Hello, World!);
Presentation transcript:

© 2006 Pearson Addison-Wesley. All rights reserved Design by Prototype Programmers often approach a problem by creating a series of prototypes. Each prototype is intended to make progress toward the desired final program. Example: an program Prototype 1: only allows the user to read messages. Prototype 2: allows the user to read and write text-only messages. Prototype 3: adds support for attachments to Prototype 3. Prototype 4: adds facilities for an address book and message flagging. Prototype 5: has better user interface in response to customer testing.... Example: an program Prototype 1: only allows the user to read messages. Prototype 2: allows the user to read and write text-only messages. Prototype 3: adds support for attachments to Prototype 3. Prototype 4: adds facilities for an address book and message flagging. Prototype 5: has better user interface in response to customer testing.... A prototype is a program with only partial functionality. (i.e., it is incomplete with respect to the requirements) Definition

© 2006 Pearson Addison-Wesley. All rights reserved Program Requirements: Create the following window. How would you design this program using a prototyping approach?

© 2006 Pearson Addison-Wesley. All rights reserved Debugging The process of identifying and correcting program errors is called debugging. The compiler captures syntax errors. However, programmers need to capture their own logic errors. Two programmer “ tricks ” for locating logic errors comment out code bracket selected regions of code with /*... */ and observe the behavior of the resulting program. intersperse System.out.println s include println instructions to display selected parts of the state and analyze the output of the resulting program.

© 2006 Pearson Addison-Wesley. All rights reserved Commenting out code Consider the following erroneous attempt at a canoe prototype. Desired window Actual window The faulty code is on the next page...

© 2006 Pearson Addison-Wesley. All rights reserved import java.awt.Color; impor t javax.swing.JFrame; public class Driver { private JFrame theWindow; private Rectangle hull; pr ivate Oval bow, stern, cover; /** post: a window is constructed and a canoe on a white background displayed. */ public Driver() { theWindow = new JFrame( "Canoe" ); theWindow.setBounds( 30, 30, 280, 240 ); theWindow.setLayout(null); theWindow.setVisible(true); theWindow.getContentPane().setBackground( Color.white ); hull = new Rectangle( 40, 90, 200, 51 ); hull.setBackground( Color.lightGray ); theWindow.add( hull, 0 ); bow = new Oval( 20, 80, 40, 60 ); bow.setBackground( Color.lightGray ); theWindow.add( bow, 0 ); stern = new Oval( 220, 80, 40, 60 ); stern.setBackground( Color.lightGray ); theWindow.add( stern, 0 ); cover = new Oval( 20, 6, 240, 100 ); cover.setBackground( Color.white ); theWindow.add( cover ); theWindow.repaint(); } import java.awt.Color; impor t javax.swing.JFrame; public class Driver { private JFrame theWindow; private Rectangle hull; pr ivate Oval bow, stern, cover; /** post: a window is constructed and a canoe on a white background displayed. */ public Driver() { theWindow = new JFrame( "Canoe" ); theWindow.setBounds( 30, 30, 280, 240 ); theWindow.setLayout(null); theWindow.setVisible(true); theWindow.getContentPane().setBackground( Color.white ); hull = new Rectangle( 40, 90, 200, 51 ); hull.setBackground( Color.lightGray ); theWindow.add( hull, 0 ); bow = new Oval( 20, 80, 40, 60 ); bow.setBackground( Color.lightGray ); theWindow.add( bow, 0 ); stern = new Oval( 220, 80, 40, 60 ); stern.setBackground( Color.lightGray ); theWindow.add( stern, 0 ); cover = new Oval( 20, 6, 240, 100 ); cover.setBackground( Color.white ); theWindow.add( cover ); theWindow.repaint(); } What if we comment out the code involving cover ?

© 2006 Pearson Addison-Wesley. All rights reserved import java.awt.Color; impor t javax.swing.JFrame; public class Driver { private JFrame theWindow; private Rectangle hull; pr ivate Oval bow, stern, cover; /** post: a window is constructed and a canoe on a white background displayed. */ public Driver() { theWindow = new JFrame( "Canoe" ); theWindow.setBounds( 30, 30, 280, 240 ); theWindow.setLayout(null); theWindow.setVisible(true); theWindow.getContentPane().setBackground( Color.white ); hull = new Rectangle( 40, 90, 200, 51 ); hull.setBackground( Color.lightGray ); theWindow.add( hull, 0 ); bow = new Oval( 20, 80, 40, 60 ); bow.setBackground( Color.lightGray ); theWindow.add( bow, 0 ); stern = new Oval( 220, 80, 40, 60 ); stern.setBackground( Color.lightGray ); theWindow.add( stern, 0 ); /* cover = new Oval( 20, 6, 240, 100 ); cover.setBackground( Color.white ); theWindow.add( cover ); */ theWindow.repaint(); } Commenting out code is good for narrowing down the error ’ s source. Be careful not to attempt nesting of comments.

© 2006 Pearson Addison-Wesley. All rights reserved System.out.println Java includes a special method (println) that can be used to output the state of any object. Desired window Actual window System.out.println( o bjectReference ); The faulty code is on the next page...

© 2006 Pearson Addison-Wesley. All rights reserved import java.awt.Color; impor t javax.swing.JFrame; public class Driver { private JFrame theWindow; private Rectangle hull; pr ivate Oval bow, stern, cover; /** post: a window is constructed and a canoe on a white background displayed. */ public Driver() { theWindow = new JFrame( "Canoe" ); theWindow.setBounds( 30, 30, 280, 240 ); theWindow.setLayout(null); theWindow.setVisible(true); theWindow.getContentPane().setBackground( Color.white ); hull = new Rectangle( 40, 90, 200, 51 ); hull.setBackground( Color.lightGray ); theWindow.add( hull, 0 ); bow = new Oval( 20, 80, 40, 60 ); bow.setBackground( Color.lightGray ); theWindow.add( bow, 0 ); stern = new Oval( 20, 80, 40, 60 ); stern.setBackground( Color.lightGray ); theWindow.add( stern, 0 ); cover = new Oval( 20, 6, 240, 100 ); cover.setBackground( Color.white ); theWindow.add( cover, 0 ); theWindow.repaint(); } import java.awt.Color; impor t javax.swing.JFrame; public class Driver { private JFrame theWindow; private Rectangle hull; pr ivate Oval bow, stern, cover; /** post: a window is constructed and a canoe on a white background displayed. */ public Driver() { theWindow = new JFrame( "Canoe" ); theWindow.setBounds( 30, 30, 280, 240 ); theWindow.setLayout(null); theWindow.setVisible(true); theWindow.getContentPane().setBackground( Color.white ); hull = new Rectangle( 40, 90, 200, 51 ); hull.setBackground( Color.lightGray ); theWindow.add( hull, 0 ); bow = new Oval( 20, 80, 40, 60 ); bow.setBackground( Color.lightGray ); theWindow.add( bow, 0 ); stern = new Oval( 20, 80, 40, 60 ); stern.setBackground( Color.lightGray ); theWindow.add( stern, 0 ); cover = new Oval( 20, 6, 240, 100 ); cover.setBackground( Color.white ); theWindow.add( cover, 0 ); theWindow.repaint(); }

© 2006 Pearson Addison-Wesley. All rights reserved import java.awt.Color; impor t javax.swing.JFrame; public class Driver { private JFrame theWindow; private Rectangle hull; private Oval bow, stern, cover; /** post: a window is constructed and a canoe on a white background displayed. */ public Driver() { theWindow = new JFrame( "Canoe" ); theWindow.setBounds( 30, 30, 280, 240 ); theWindow.setLayout(null); theWindow.setVisible(true); theWindow.getContentPane().setBackground( Color.white ); hull = new Rectangle( 40, 90, 200, 51 ); hull.setBackground( Color.lightGray ); theWindow.add( hull, 0 ); System.out.println( hull ); bow = new Oval( 20, 80, 40, 60 ); bow.setBackground( Color.lightGray ); theWindow.add( bow, 0 ); stern = new Oval( 20, 80, 40, 60 ); stern.setBackground( Color.lightGray ); theWindow.add( stern, 0 ); System.out.println( bow ); System.out.println( stern ); cover = new Oval( 20, 6, 240, 100 ); cover.setBackground( Color.white ); theWindow.add( cover, 0 ); theWindow.repaint(); } import java.awt.Color; impor t javax.swing.JFrame; public class Driver { private JFrame theWindow; private Rectangle hull; private Oval bow, stern, cover; /** post: a window is constructed and a canoe on a white background displayed. */ public Driver() { theWindow = new JFrame( "Canoe" ); theWindow.setBounds( 30, 30, 280, 240 ); theWindow.setLayout(null); theWindow.setVisible(true); theWindow.getContentPane().setBackground( Color.white ); hull = new Rectangle( 40, 90, 200, 51 ); hull.setBackground( Color.lightGray ); theWindow.add( hull, 0 ); System.out.println( hull ); bow = new Oval( 20, 80, 40, 60 ); bow.setBackground( Color.lightGray ); theWindow.add( bow, 0 ); stern = new Oval( 20, 80, 40, 60 ); stern.setBackground( Color.lightGray ); theWindow.add( stern, 0 ); System.out.println( bow ); System.out.println( stern ); cover = new Oval( 20, 6, 240, 100 ); cover.setBackground( Color.white ); theWindow.add( cover, 0 ); theWindow.repaint(); }