CSE 1020:Programming by Delegation

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
ITEC200 Week01 Introduction to Software Design.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Fall 2007CS 225 Introduction to Software Design Chapter 1.
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Class Design Lecture 6, Tue Jan
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Spring 2009CS 225 Introduction to Software Design Chapter 1.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Writing Classes (Chapter 4)
Java Classes Using Java Classes Introduction to UML.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Introduction to Software Design Chapter 1. Chapter Objectives  To become familiar with the software challenge and the software life cycle  To understand.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Software Life Cycle Requirements and problem analysis. –What exactly is this system supposed to do? Design –How will the system solve the problem? Coding.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Utilities (Part 2) Implementing static features 1.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 4.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
Object Oriented Programming with Java 03 - Introduction to Classes and Objects.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
1  lecture slides online
By Mr. Muhammad Pervez Akhtar
Creating a Java Application and Applet
COM S 228 Introduction to Data Structures Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff.
The Hashemite University Computer Engineering Department
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
CSE 1030: Implementing Static Features Mark Shtern.
Topics Instance variables, set and get methods Encapsulation
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
CSE 1020: Exceptions and A multiclass application Mark Shtern 1-1.
CSE 1020:Using Objects Mark Shtern 1-1. Summary Read API Method binding and overloading Development process Input validation Assert 1-2.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
CS16: UML’s Unified Modeling Language. UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
CSE 1020:Using API Mark Shtern 1-1. Summary Delegation – Static Method, Object Client view vs Implementer view API, UML Errors Software Engineering Utility.
Lecture 7 D&D Chapter 7 & 8 Composite Classes and enums Date.
Software Development I/O and Numbers
About the Presentations
CompSci 230 Software Construction
Data types, Expressions and assignment, Input from User
Comp Sci 200 Programming I Jim Williams, PhD.
Something about Java Introduction to Problem Solving and Programming 1.
INPUT STATEMENTS GC 201.
Creating and Using Classes
CSE 1020: Introduction to Computer Science I
CSE 1030: Implementing Mixing static and non-static features
CSE 1030: Implementing Non-Static Features
Slides by Steve Armstrong LeTourneau University Longview, TX
Implementing Non-Static Features
More on Classes and Objects
CSE 1020:Inheritance Mark Shtern.
CS 200 Primitives and Expressions
CS100J Lecture 7 Previous Lecture This Lecture Java Constructs
CS 200 Primitives and Expressions
Week 4 Lecture-2 Chapter 6 (Methods).
CS2011 Introduction to Programming I Elementary Programming
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
CS Week 2 Jim Williams, PhD.
CSE 1020:Software Development
Chapter 7 Objects and Classes
Presentation transcript:

CSE 1020:Programming by Delegation Mark Shtern

Summary Java VM Edit-Compile-Run cycle Edit Compile Run Create or edit Save Compile Run Lunch main class Interact with user

Summary Math & Computer Memory and Declaration

Delegation Delegating to a static Method Delegating to an Object int width = 8; int height = 3; int area = width * height; Delegating to a static Method int area = Rectangle.area(8 , 3); Delegating to an Object Rectangle rectangle = new Rectangle(8,3); int area = rectangle.getArea();

Client View Encapsulation, information hiding A component can be improved without impact on client feature attribute method private public = field public API- Application Programming Interface

Contracts Precondition - the client’s responsibility Postcondition – the implementer’s responsibility

Example 01 Write a program that outputs the return of the getTime and toString methods of Date class whose UML diagram is shown below

Exercises 2.4 The following fragment uses a method in a class whose UML diagram is shown below. Do you see any compile-time errors? double amount = 2500; Int period = 4; double pay = Orbit.payBack(amount,period);

Exercises 2.5 The following fragment uses a method in a class whose UML diagram is shown below. Do you see any compile-time errors? int amount = 2500; Int period = 4; double pay = Orbit.payBack(amount,period);

Exercises 2.6 The following fragment uses a method in a class whose UML diagram is shown below. Do you see any compile-time errors? float amount = 2500; Int period = 4; double pay = Orbit.payBack(amount,period);

Exercises 2.7 The following fragment uses a method in a class whose UML diagram is shown below. Do you see any compile-time errors? double amount = 2500; long period = 4; double pay = Orbit.payback(amout,period);

Exercises 2.8 The following fragment uses a method in a class whose UML diagram is shown below. Do you see any compile-time errors? double amount = 2500; int period = 4; Int pay = Orbit.payback(amout,period);

Exercises 2.9 The following fragment uses a method in a class whose UML diagram is shown below. Do you see any compile-time errors? Bond.rating = ‘C’; Bond.rate = 0.12; double x = Bound.estimate(); output.println (Bound.inflate());

Exercises 2.10 The following fragment uses a method in a class whose UML diagram is shown below. Do you see any compile-time errors? Bond.rating = ‘C’; Bond.rate = 0.12; Bound.estimate(); Bound.inflate();

Summary Delegation Types and Casting Complexity Reduction Static Method Object Method Types and Casting

Method Signature Return Visibility name together with the types of parameters sin(double) getArea() Return Type such as void, double, int etc Visibility Private/Public

UML Unified Modelling Language

Utility Class Utility Class all method are static Utility Class may contains constant UML Attributes Methods

Objects Is a software entity that is capable of storing data as well as performing computations Object has Attributes Methods State Reference

Object Features Rectangle rectangle = new Rectangle(4,5) Methods Attributes Rectangle rectangle = new Rectangle(4,5) Class reference Instantiation

Class Attributes Attributes Field Private Constructors Methods Methods

API Complexity Accountability Substitutability

Software Engineering Patterns Risk Mitigation by Early Exposure Handling Constants Contracts Precondition Postcondition

1020 Templet Import java.util.Scanner Import java.io.PrintStream public class Templet { public static void main(String[] args) Scanner input = new Scanner (System.in); PrintStream output = System.out; .... }

I/O Input from keyboard Output on screen input.nextInt() output.println()

Errors Compilation Errors Post-Compilation Errors Run-time Errors Logical Errors

Post-Compilation Errors Understand root of problem Input Location Modify application Verify solution Re-test application

Debugging Techniques Add print statements Comment code

Exercises 2.12 The following fragment computes the average of three variables: int x = 6/2; int y = 12 / (x - 3); int z = - 3; double mean = x + y + z )/3; It contains a compile-time, a runtime error and a logical error. Identify each.

Exercises 2.13 A Develop decided to declare 5/9 literal as a final and gave it the identifier SCALE_FACTOR Which of the following declaration does not lead to a logical error final double SCALE_FACTOR = 5 / 9; final double SCALE_FACTOR = 5.0 / 9.0; final double SCALE_FACTOR = 5 / 9.0; final double SCALE_FACTOR = (double)(5 / 9); final double SCALE_FACTOR = (double) 5/ 9; final double SCALE_FACTOR = 5/(double)9;

Exercises 2.14 Rewrite the following fragment so that it is free of magic numbers: output.println (“Enter speed in km/h”); double speed = input.nextDouble(); speed = speed * 1000 / 3600; output.println (“Enter speed in ft”); double distance = distance * 0.3048; double time = distance/speed;