Topics. The Development Process

Similar documents
Using APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI

Java Classes: Math, Integer A C S L E C T U R E 8

In this lab we will practice creating, throwing and handling exceptions.

CEN 414 Java Programming

Programming by Delegation

Chapter 2 ELEMENTARY PROGRAMMING

Chapter 2 Primitive Data Types and Operations. Objectives

STUDENT LESSON A7 Simple I/O

Full file at

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Chapter 02: Using Data

4 WORKING WITH DATA TYPES AND OPERATIONS

Chapter 2: Using Data

19. GUI Basics. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

OBJECT ORIENTED PROGRAMMING IN JAVA

Full file at

JAVA Programming Concepts

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Full file at

Full file at

Chapter 2 Elementary Programming

CS111: PROGRAMMING LANGUAGE II

Chapter 2: Using Data

Numerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Date: Dr. Essam Halim

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

First Java Program - Output to the Screen

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

COMP 202 Java in one week

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Elementary Programming

Computer Components. Software{ User Programs. Operating System. Hardware

Midterm Examination (MTA)

COMP 202 Java in one week

Motivations 9/14/2010. Introducing Programming with an Example. Chapter 2 Elementary Programming. Objectives

Section 2.2 Your First Program in Java: Printing a Line of Text

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Introduction to Java Applications

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Chapter 2 Elementary Programming

Simple Java Reference

Object Oriented Programming. Java-Lecture 1

Supplement D: Expanded Guidelines on Programming Style and Documentation

2.5 Another Application: Adding Integers

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

COMP 202. Java in one week

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Introduction to Computers and Engineering Problem Solving 1.00 / Fall 2004

Java Libraries. Lecture 6 CGS 3416 Fall September 21, 2015

BASIC INPUT/OUTPUT. Fundamentals of Computer Science

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Chapter 2. Elementary Programming

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

JAVA Ch. 4. Variables and Constants Lawrenceville Press

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

Data Types Reference Types

Chapter 3. Selections

Computational Expression

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

What did we talk about last time? Examples switch statements

Java Errors and Exceptions. Because Murphy s Law never fails

Full file at

2/9/2012. Chapter Four: Fundamental Data Types. Chapter Goals

Chapter 3 Selection Statements

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

PRIMITIVE VARIABLES. CS302 Introduction to Programming University of Wisconsin Madison Lecture 3. By Matthew Bernstein

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Computer Components. Software{ User Programs. Operating System. Hardware

2.8. Decision Making: Equality and Relational Operators

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

Fundamentals of Programming Session 4

Anatomy of a Java Program: Comments

Chapter 2: Data and Expressions

Formatted Output (printf) CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Warm up Exercise. What are the types and values of the following expressions: * (3 + 1) 3 / / 2.0 (int)1.0 / 2

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Course PJL. Arithmetic Operations

Chapter 2 Primitive Data Types and Operations

Java Coding 3. Over & over again!

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

Introduction to Java Applications; Input/Output and Operators

Chapter 12 Exception Handling

4. Java Project Design, Input Methods

Java Console Input/Output The Basics. CGS 3416 Spring 2018

Java Reference Card. 1. Classes. 2. Methods. 3. Conditionals. 4. Operators

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Getting started with Java

Introduction to Programming Using Java (98-388)

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Class 9: Static Methods and Data Members

Chapter 5 Lab Methods

Expanded Guidelines on Programming Style and Documentation

double float char In a method: final typename variablename = expression ;

Transcription:

Topics Anatomy of an API A development walkthrough General characteristics of utility classes 8 The Development Process Analysis Design Implementation Testing Deployment 9 1

The Development Process Analysis Design The requirement: Input and its validation Output and its formatting Implementation Testing Deployment 10 Analysis The Development Process Design An algorithm (function) that determines the output given the input Implementation Testing Deployment 11 2

Analysis The Development Process Design Implementation Turn the algorithm into a program Testing Deployment 12 Analysis The Development Process Design Implementation Testing Does the program meet the requirement? Deployment 13 3

Analysis The Development Process Design Implementation Testing Deployment Installing, porting, training, support 14 The Mortgage Application - Analysis Requirement Compute the monthly payment of a mortgage 15 4

The Mortgage Application - Analysis Requirement Compute the monthly payment of a mortgage Input Mortgage amount; annual interest percent; both reals Validation: amount > 0; interest in range (0, 100) 16 The Mortgage Application - Analysis Requirement Compute the monthly payment of a mortgage Input Mortgage amount; annual interest percent; both reals Validation: amount > 0; interest in range (0, 100) Output Monthly payment Formatting: rounded to the nearest cent; thousands separator 17 5

The Mortgage Application - Analysis Sample run of proposed program: Enter the amount 285000 The annual interest percent 375 The monthly payment is: $1,46527 18 The Mortgage Application - Design P 1 ra 1 (1 r) n P is the monthly payment, r is the monthly interest rate, A is the mortgage amount, and n is the number of months (We'll assume a 25-year amortization) 19 6

The Mortgage Application - Implementation Implement a class to take care of prompts and inputs Ignore validation for now We ll do the computation ourselves with the help of A class that computes powers A class for output Ignore formatting for now 20 Implementation Notes The importance of prompting Using print versus println Use the next methods of Scanner Converting from an annual percent to a monthly rate Hard-coded constants like 12 are a source of confusion; using final 21 7

Mortgage01java First Attempt In-class Note: View from Eclipse 22 The printf method Output Formatting The first parameter holds format specifiers Each specifier has the form: %[flag][width][precision]conversion The conversion letter can be d, f, s, or n The flag can be, or 0 (, = thousands separator; 0 = pad left with zeros) The width specifies the minimum field width and the precision specifies the number of decimals Example outputprintf("%,62f", x); 23 8

Second Attempt (with printf) Mortgage02java Instructor Note: View from Eclipse 24 Relational Operators Relational operators take two operands and produce a boolean result < <= > >= Numeric operands ==!= Operands of any type 25 9

Precedence (add to previous table) Precedence Operator Operands Syntax true if < numeric x < y x is less than y <= numeric x <= y x is less than or equal to y -7 > numeric x > y x is greater than y >= numeric x >= y x is greater than or equal to y instanceof x instanceof C is true if object reference x points to an instance of class C or a subclass of C -8 == any type x == y x is equal to y!= any type x!= y x is not equal to y 26 Input Validation Invalid inputs are the cause of most errors in programs Therefore, upon encountering one, a program has three options: 1 Print a message and end 2 Print a message then allow the user to retry several times or decide to abort 3 Trigger a runtime error; ie, crash For now, let us use the 3 rd option via a method in Toolbox: static void crash(boolean, String) 27 10

Third Attempt (with crash) Mortgage03java Instructor Note: View from Eclipse 28 Assertions A simple yet powerful tool to guard against errors that arise from misunderstandings If you believe some non-trivial condition is true, assert it, eg assert payment >=0; You cannot assert a validation because user input is not under the programmer's control Hence, do not confuse assert (a Java statement) with crash (a method) 29 11

Topics Anatomy of an API A development walkthrough General characteristics of utility classes 30 Memory Diagrams Compile, load, and run Circlejava (which uses a field and method in the Math utility class) import javautilscanner; import javaioprintstream; public class Circle { public static void main(string[] args) { Scanner input = new Scanner(Systemin); PrintStream output = Systemout; outputprint("enter radius: "); int radius = inputnextint(); outputprintln(mathpi * Mathpow(radius, 2)); } } 31 12

Memory Diagrams (2) Before looking at a memory diagram, improve Circlejava by printing the area with some lead-in text and displaying the area to two decimal places 32 Memory Diagrams radius 0 1 64 80 Circle PI pow 800 824 880 Math 33 13

Advantages of Utility Classes Simplicity To access a static field f in a class C, write: Cf To invoke a static method m in a class C, write Cm( ) There is only one copy of a static class in memory Suitability A utility class is best suited to hold a group of methods that do not hold state, eg, javalangmath Even in non-utility classes, static is best suited for features that are common to all instances, eg the MAX_VALUE field and the parseint method of the (non-utility) class Integer 34 Case Study: Dialog I/O Consider two static methods in: javaxswingjoptionpane To display a message: void showmessage(null, message) To prompt for and read an input: String showinputdialog(null, prompt) Note: showinputdialog returns a String To read a number, you must invoke one of the parse methods in the corresponding wrapper class (eg, Integer, Double) 35 14

The Mortgage Application (using JOptionPane) Mortgage04java Instructor Note: View from Eclipse 36 Thank You 37 15