Software Engineering (Chap. 1) Object-Centered Design When we prepare a program, the experience can be just like composing poetry or music … My claim is.

Slides:



Advertisements
Similar presentations
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
1 © 1998, 2001, 2002Calvin College, Keith Vander Linden, Jeremy D. Frens, Larry R. Nyhoff Objects (Chap. 2) Variables and Constants.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
How to Create a Java program CS115 Fall George Koutsogiannakis.
Getting Started with Java
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
 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.
Computer Programming 1 Problem Solving and Software Engineering.
Begin Java having used Alice Pepper - Some slides from Alice in Action with Java.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Software Engineering 1 (Chap. 1) Object-Centered Design.
1 4.3 Example: Volume of a Sphere Given the radius r, what is the weight of a ball (sphere) of wound twine?Given the radius r, what is the weight of a.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
1 Programming and Problem Solving — Software Engineering (Read Chap. 2)
Programming and Problem Solving — Software Engineering (Read Chap. 2) 1.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Alice in Action with Java Chapter 7 From Alice to Java.
Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Programming Lifecycle
The Java Programming Language
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
1 Chapter-01 Introduction to Software Engineering.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
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.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 An Example. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian Rules Football field, which.
1 An Example. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian Rules Football field, which.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
1 Chapter-01 Introduction to Software Engineering.
1 Operations Making Things Happen (Chap. 3) Expressions.
1 Simple Methods Chap. 4 Study Sections 4.1 – 4.4 Writing Reusable Formulas.
CSC Programming I Lecture 6 September 4, 2002.
Identifiers Identifiers in Java are composed of a series of letters and digits where the first character must be a letter. –Identifiers should help to.
Software Engineering Object-Centered Design. Problem Solving Does anyone scuba dive? Let’s solve this scuba-diving problem: Write a program that, given.
1 Simple Methods Chap. 4 Study Sections 4.1 – 4.4 Writing Reusable Formulas.
Creating a Java Application and Applet
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
The Hashemite University Computer Engineering Department
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
1 Chapter-01 Introduction to Software Engineering.
11 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
CS 177 Recitation Week 1 – Intro to Java. Questions?
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Chapter 3 GC 101 Java Fundamentals.
Introduction to.
String Output ICS 111: Introduction to Computer Science I
MSIS 655 Advanced Business Applications Programming
Java Intro.
Anatomy of a Java Program
Computer Programming-1 CSC 111
Object-Centered Design
Presentation transcript:

Software Engineering (Chap. 1) Object-Centered Design When we prepare a program, the experience can be just like composing poetry or music … My claim is that it is possible to write grand programs, noble programs, truly magnificent ones!... Computer programming is an art. - Donald Knuth, “Programming as an Art”, 1974

Problem Solving Let’s solve this temperature-conversion problem: Write a program that, given a temperature in Celsius, displays that temperature in Fahrenheit. 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance OCD (Object-Centered Design) 2

OCD in a Nutshell Behavior Objects Operations Algorithm

Behavior A. Describe the desired behavior of the program: Our program should display a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display that temperature along with a descriptive label on the screen. 4 Using OCD

Objects B. Identify the nouns in the behavioral description: Our program should display a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display that temperature along with a descriptive label on the screen. These make up the objects in our program. 5 Using OCD

Operations These make up the operations in our program. C. Identify the verbs in the behavioral description: Our program should display a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display that temperature along with a descriptive label on the screen. 6 Using OCD

Algorithm D. Organize the objects and operations into a sequence of steps that solves the problem, called an algorithm. 1. Ask the screen to display a prompt for the Celsius temperature on the screen. 2. Ask the keyboard to read the temperature. 3. Compute the Fahrenheit temperature from the Celsius temperature. 4. Ask the screen to display the Fahrenheit temperature, plus an informative label on the screen. 7 Using OCD

Don’t even think about coding until you’re sure of your algorithm.

Coding We now translate the algorithm into an HLL. Use the features of the Java language to: –represent our objects –perform our operations Java provides two implementation methods: –Java applications –Java applets (Sec. 1.3)

Java Applications Programming languages traditionally allow programmers to write stand-alone applications. In Java, these are called applications. Compiler A Java Application Program Interpreter The byte-code for the application javac java Abc.java Abc.class

Representing Objects Determine a type and name for each object:

Performing Operations Identify the Java operator to perform a given operation, if there is one… To compute the Fahrenheit temperature, we need to find the Celsius to Fahrenheit formula in a reference book... fahrenheit = (9/5)celsius + 32

Operations (Revised) We can now add more detail to the computation: doubles

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { public static void main(String [] args) { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in Celsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } The Code Objects? Operations?

COMPILATION HINT Use the tools available to you. Specifically, use M-x compile in xemacs. – Use C-x ` to run through the error messages.  Xemacs will automatically go to the next message.  It will even load in the proper file and go to the offending line.  Why do you want to do this work? –Run only one session of xemacs; open multiple files into the same session. –If you aren't comfortable or used to it, practice. (or middle mouse button)

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { public static void main(String [] args) { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in Celsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } Documentation Always begin a file with an opening comment similar to this.. 3 Kinds of Comments: /*...*/ multi-line comment // single-line comment -- indicate what classes of a package are used. -- explain obscure code /**...*/ Javadoc multi-line comment javadoc program extracts these into special documentation.format -- see Java'sAPI (Section 2.4) Compiler ignores all comments

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { public static void main(String [] args) { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in Celsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } Import Section This loads the Java packages that we need. Packages: -- Groups of related classes e.g., easyio -- Often grouped into libraries e.g., ann -- Java has > 1600 classes grouped into several packages -- see its API Use import package_name.*; to make classes in a package easily accessible

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in Celsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } The Class Definition Java programs are classes built upon existing classes Form: class Class_name extends Object { public static void main(String[] args) { statements } } -- Use meaningful class name -- Capitalize it -- Save program as Class_name.java

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { public static void main(String [] args) { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in Celsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } The Main Method Java applications begin execution by running main()

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { public static void main(String [] args) { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in delsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } Step 1 Print a friendly message.

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { public static void main(String [] args) { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in Celsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } Step 2 Read the Celsius temperature.

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { public static void main(String [] args) { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in Celsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } Step 3 Calculate the Fahrenheit temperature.

/* Temperature.java converts Celsius * temperatures to Fahrenheit. * Author: Keith Vander Linden * Date: 2 June 2001 * Modified: L. Nyhoff, Sept */ import ann.easyio.*; // Screen & Keyboard classes class Temperature extends Object { public static void main(String [] args) { Screen theScreen = new Screen(); theScreen.print("Welcome to the temperature converter!\n" + "Please enter the temperature in Celsius: "); Keyboard theKeyboard = new Keyboard(); double celsius = theKeyboard.readDouble(); double fahrenheit = ((9.0/5.0)*celsius) + 32; theScreen.print(celsius + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.\n" + "It's been a pleasure!\n"); } Step 4 Display the results.

Running the Program You can now run your application: Welcome to the temperature converter! Please enter the temperature in Celsius: degrees Celsius is 68.0 degrees Fahrenheit. It's been a pleasure!

Testing Getting your code to compile and run is not the main goal. Rather, your goal is to produce a useful program that is: –correct –efficient –readable –usable

Running Test Cases Do many tests on “interesting” data points. Welcome to the temperature converter! Please enter the temperature in Celsius: degrees Celsius is 32.0 degrees Fahrenheit. It's been a pleasure! Welcome to the temperature converter! Please enter the temperature in Celsius: degrees Celsius is degrees Fahrenheit. It's been a pleasure!

Writing Code Comments ( /*... */ or // ) are completely ignored by the compiler. Whitespace matters only two places: –Inside quotes, and – In comment delimiters ( /*, */, // ). A semi-colon indicates the end of a program statement.

COMPILATION HINT Forgotten or extra semi-colons confuse the compiler. The compiler never recognizes that there's a semi-colon problem; it usually won't say what's wrong. Usually a "parse error" is an indication that the previous line of code is missing a semi- colon or has one it shouldn't.