Problem Solving. Software Engineering. Behavior. OCD in a Nutshell. Behavior. Objects Operations Algorithm. Object-Centered Design



Similar documents
Some Scanner Class Methods

Chapter 3. Input and output. 3.1 The System class

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

Chapter 1 Java Program Design and Development

1001ICT Introduction To Programming Lecture Notes

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Introduction to programming

Java Crash Course Part I

Moving from CS 61A Scheme to CS 61B Java

Java CPD (I) Frans Coenen Department of Computer Science

6.1. Example: A Tip Calculator 6-1

Lecture 5: Java Fundamentals III

Introduction to Java

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

LAB4 Making Classes and Objects

CS 106 Introduction to Computer Science I

Install Java Development Kit (JDK) 1.8

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

More on Objects and Classes

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

An Overview of Java. overview-1

Programmierpraktikum

CS170 Lab 11 Abstract Data Types & Objects

Comp 248 Introduction to Programming

Data Structures Lecture 1

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Building Java Programs

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Using Files as Input/Output in Java 5.0 Applications

Using EDA Databases: Milkyway & OpenAccess

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Java Classes. GEEN163 Introduction to Computer Programming

Installing Java. Table of contents

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Sample CSE8A midterm Multiple Choice (circle one)

Example of a Java program

Getting Started with the Internet Communications Engine

Chapter 2 Elementary Programming

AP Computer Science Static Methods, Strings, User Input

Building Java Programs

ECE 122. Engineering Problem Solving with Java

Extending Desktop Applications to the Web

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Java with Eclipse: Setup & Getting Started

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Manual For Using the NetBeans IDE

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Introduction to Java. CS 3: Computer Programming in Java

CPLEX Tutorial Handout

Chapter 2 Introduction to Java programming

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Basics of Java Programming Input and the Scanner class

Introduction to Object-Oriented Programming

CS106A, Stanford Handout #38. Strings and Chars

Syllabus for CS 134 Java Programming

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Java Program Coding Standards Programming for Information Technology

2 Getting Started with jgrasp 2.0

Programming Languages CIS 443

WIRIS quizzes web services Getting started with PHP and Java

Computer Programming Tutorial

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Chapter 1 Introduction to Computers, Programs, and Java

Crash Course in Java

With a single download, the ADT Bundle includes everything you need to begin developing apps:

AP Computer Science Java Subset

University of Pennsylvania. Electrical & Systems Engineering Undergraduate Laboratories. ESE 112: Introduction to Electrical & Systems Engineering

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Chapter 2 Writing Simple Programs

Chapter 1. Introduction to Computers, Programs, and Java

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Computer Programming C++ Classes and Objects 15 th Lecture

03 - Lexical Analysis

Week 2 Practical Objects and Turtles

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

CSE 308. Coding Conventions. Reference

Writing Simple Programs

Building Java Programs

Introduction to Programming

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

FEEG Applied Programming 5 - Tutorial Session

Supplement I.C. Creating, Compiling and Running Java Programs from the Command Window

Programming and Data Structures with Java and JUnit. Rick Mercer

TABLE OF CONTENTS...2 INTRODUCTION...3 APPLETS AND APPLICATIONS...3 JAVABEANS...4 EXCEPTION HANDLING...5 JAVA DATABASE CONNECTIVITY (JDBC)...

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes

(Eng. Hayam Reda Seireg) Sheet Java

Transcription:

Software Engineering (Chap. 1) Object-Centered Design Problem Solving Let s solve this temperature-conversion problem: Write a program that, given a temperature in Celsius, displays that temperature in Fahrenheit. 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 5 Phases of Software Life Cycle: Problem Analysis and Specification Design (Object-Centered Design) Implementation (Coding) Testing, Execution and Debugging Maintenance 2 in a Nutshell Using Behavior Behavior Objects Operations Algorithm 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 1

Using Objects Using Operations 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. 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. These make up the operations in our program. 5 6 Using 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. Don t even think about coding until you re sure of your algorithm. 7 2

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. Abc.java A Java Application Program Compiler javac Abc.class The byte-code for the application Interpreter java Representing Objects Performing Operations Determine a type and name for each object: Identify the Java operator to perform a given operation, if there is one ObjectJava TypeNamethe programa promptthe Celsius temp.the screenthe keyboardthe Fahrenheit OperationLibrary?NameDisplay temp.a labelobjectstringdoublescreenkeyboarddoublestringtemperatur a stringread a doublecompute fahrenheitdisplay a doublean To compute the Fahrenheit temperature, we need to find the Celsius to Fahrenheit formula in a reference book... fahrenheit = (9/5)celsius + 32 3

Operations (Revised) We can now add more detail to the computation: Operation Library? Name Display a string Read a double Compute fahrenheit Divide two ints doubles Multiply two doubles Add two doubles Display a double ann.easyio ann.easyio -- built-in built-in built-in ann.easyio print() readdouble() -- / * + print() The Code Objects? Operations? COMPILATION HINT Use the tools available to you. Specifically, use M-x compile in xemacs. (or middle mouse button) 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. 3 Kinds of Comments: public static void main(string /*... [] args) multi-line comment // single-line comment -- indicate what classes of a package are used. "Please enter -- explain the obscure temperature code in Celsius: "); Documentation Always begin a file with an opening comment similar to this.. /**... Javadoc multi-line comment javadoc program extracts these into special documentation.format double fahrenheit = ((9.0/5.0)*celsius) -- see Java'sAPI (Section + 32; 2.4) thescreen.print(celsius Compiler + " degrees ignores Celsius all comments is " + 4

Import Section This loads the Java packages that we need. The Class Definition Java programs are classes built upon existing classes Packages: public static void main(string -- Groups [] args) of related classes e.g., easyio thescreen.print("welcome -- to Often the grouped temperature into libraries converter!\n" + "Please enter e.g., the anntemperature in Celsius: "); Keyboard thekeyboard = new -- Java Keyboard(); has > 1600 classes grouped into several packages -- see its API Use import package_name.*; thescreen.print(celsius + to " make degrees classes Celsius in a package is " + easily fahrenheit accessible + " degrees Fahrenheit.\n" + Screen thescreen Form: = new Screen(); class Class_name extends Object Keyboard thekeyboard public = new static Keyboard(); void main(string[] args) statements double fahrenheit = ((9.0/5.0)*celsius) + 32; -- fahrenheit Use meaningful + " class degrees namefahrenheit.\n" + -- Capitalize it -- Save program as Class_name.java The Main Method Java applications begin execution by running main() "Please enter the temperature in delsius: "); Step 1 Print a friendly message. 5

public static void main(string [] Read args) the Celsius temperature. Step 2 Step 3 Calculate the thescreen.print("welcome to the Fahrenheit temperature temperature. converter!\n" + thescreen.print("welcome to the temperature Step converter!\n" 4 + Display the results. Running the Program You can now run your application: Welcome to the temperature converter! Please enter the temperature in Celsius: 20 20.0 degrees Celsius is 68.0 degrees Fahrenheit. It's been a pleasure! 6

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: 0 0.0 degrees Celsius is 32.0 degrees Fahrenheit. It's been a pleasure! Welcome to the temperature converter! Please enter the temperature in Celsius: -17.78-17.78 degrees Celsius is -0.0040000000000048885 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 semicolon or has one it shouldn't. 7