MSIS 655 Advanced Business Applications Programming

Slides:



Advertisements
Similar presentations
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Chapter 5 C Functions The best way to develop and maintain a large program is to divide it into several smaller program modules, each of which is more.
Introduction to Computers and Programming Introduction to Methods in Java.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Math class methods & User defined methods Introduction to Computers and Programming in JAVA: V
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
 2007 Pearson Education, Inc. All rights reserved C Functions.
 2003 Prentice Hall, Inc. All rights reserved Introduction Modules –Small pieces of a problem e.g., divide and conquer –Facilitate design, implementation,
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Dale Roberts Procedural Programming using Java Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
1 Introduction Modules  Most computer programs solve much larger problem than the examples in last sessions.  The problem is more manageable and easy.
 2005 Pearson Education, Inc. All rights reserved. 1 Methods Called functions or procedures in other languages Modularize programs by separating its tasks.
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Part II © Copyright by Pearson Education, Inc. All Rights Reserved.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo CET 3640 © Copyright by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Methods: A Deeper Look. Template for Class Definition public class { } A.Import Statement B.Class Comments C.Class Name D.Data members E.Methods (inc.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 15,16 Java’s Methods.
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Introduction Modules Small pieces of a problem ▴ e.g., divide and conquer Facilitate design, implementation, operation and maintenance of large programs.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
(C) 2010 Pearson Education, Inc. All rights reserved.  Best way to develop and maintain a large program is to construct it from small, simple pieces,
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
7 Methods: A Deeper Look.
Functions and an Introduction to Recursion
“Form Ever Follows Function” Louis Henri Sullivan
Java Primer 1: Types, Classes and Operators
Methods Chapter 6.
Programming Fundamentals Lecture #7 Functions
Deitel- C:How to Program (5ed)
Switch, Rounding Errors, Libraries
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 6 Methods: A Deeper Look
Chapter 5 - Functions Outline 5.1 Introduction
Object Based Programming
Chapter 6 Methods: A Deeper Look
Week 6 Object-Oriented Programming (2): Polymorphism
6 Methods: A Deeper Look.
MSIS 655 Advanced Business Applications Programming
IFS410 Advanced Analysis and Design
Object Oriented Programming in java
CSE 1341 Topic 5 Methods © 2013 Ken Howard,
6 Methods: A Deeper Look.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
6 Methods: A Deeper Look.
6 Methods: A Deeper Look.
Object Oriented Programming in java
6 Methods: A Deeper Look.
Chapter 5 Methods: A Deeper Look
Java Methods: A Deeper Look Academic 2019 Class: BIT23/BCS10 Chapter 06 Abdulaziz Yasin Nageye Faculty of Computing Java How to Program, 10/e 1 © Co py.
6 Functions.
Presentation transcript:

MSIS 655 Advanced Business Applications Programming Week 6 Methods In this chapter you will learn: How static methods and fields are associated with an entire class rather than specific instances of the class. To use common Math methods available in the Java API. To understand the mechanisms for passing information between methods. How to use random-number generation to implement game-playing applications. 11/28/2018 6.1

Introduction Divide and conquer technique Construct a large program from smaller pieces (or modules) Can be accomplished using methods static methods can be called without the need for an object of the class Constants Random number generation 11/28/2018

Program Modules in Java Java Application Programming Interface (API) Also known as the Java Class Library Contains predefined methods and classes Related classes are organized into packages Includes methods for mathematics, string/character manipulations, input/output, databases, networking, file processing, error checking and more http://java.sun.com/j2se/5.0/docs/api/index.html Including the declaration import java.util.Scanner; allows the programmer to use Scanner instead of java.util.Scanner Java API documentation java.sun.com/j2se/5.0/docs/api/index.html Overview of packages in JDK 5.0 java.sun.com/j2se/5.0/docs/api/overview-summary.html 11/28/2018

Program Modules in Java (Cont.) Methods Called functions or procedures in other languages Modularize programs by separating its tasks into self-contained units Enable a divide-and-conquer approach Are reusable in later programs Prevent repeating code To promote software reusability, every method should be limited to performing a single, well-defined task, and the name of the method should express that task effectively. Such methods make programs easier to write, debug, maintain and modify. A small method that performs one task is easier to test and debug than a larger method that performs many tasks. 11/28/2018

static Methods, static Fields and Class Math static method (or class method) Applies to the class as a whole instead of a specific object of the class Call a static method by using the method call: ClassName.methodName( arguments ) All methods of the Math class are static example: Math.sqrt( 900.0 ) Class Math is part of the java.lang package, which is implicitly imported by the compiler, so it is not necessary to import class Math to use its methods. -Three ways to call a method: Use a method name by itself to call another method of the same class Use a variable containing a reference to an object, followed by a dot (.) and the method name to call a method of the referenced object Use the class name and a dot (.) to call a static method of a class - static methods cannot call non-static methods of the same class directly 11/28/2018

Fig. 6.2 | Math class methods. 11/28/2018

Constants Constants static fields (or class variables) Keyword final Cannot be changed after initialization static fields (or class variables) Are fields where one copy of the variable is shared among all objects of the class Math.PI and Math.E are final static fields of the Math class 11/28/2018

String concatenation Using the + operator with two Strings concatenates them into a new String Using the + operator with a String and a value of another data type concatenates the String with a String representation of the other value When the other value is an object, its toString method is called to generate its String representation It is a syntax error to break a String literal across multiple lines in a program. If a String does not fit on one line, split the String into several smaller Strings and use concatenation to form the desired String. Confusing the + operator used for string concatenation with the + operator used for addition can lead to strange results. Java evaluates the operands of an operator from left to right. For example, if integer variable y has the value 5, the expression "y + 2 = " + y + 2 results in the string "y + 2 = 52", not "y + 2 = 7", because first the value of y (5) is concatenated with the string "y + 2 = ", then the value 2 is concatenated with the new larger string "y + 2 = 5". The expression "y + 2 = " + (y + 2) produces the desired result "y + 2 = 7". 11/28/2018

Random-Number Generation static method random from class Math Returns doubles in the range 0.0 <= x < 1.0 class Random from package java.util Can produce pseudorandom boolean, byte, float, double, int, long and Gaussian values Is seeded with the current time of day to generate different sequences of numbers each time the program executes 11/28/2018

To generate a random number To generate a random number in certain sequence or range Use the expression shiftingValue + differenceBetweenValues * randomNumbers.nextInt( scalingFactor ) where: shiftingValue is the first number in the desired range of values differenceBetweenValues represents the difference between consecutive numbers in the sequence scalingFactor specifies how many numbers are in the range 11/28/2018

11/28/2018

11/28/2018

Lab activities (Week 6) Coding Assignment 5 Exercises (pp. 281-283) 6.16, 6.22, 6.30, 6.32 (Use 6.30 instead of 6.31 to base the program) This problem should be similar to the example just we reviewed. Check the examples in the book, you will be able to find necessary stuff. 11/28/2018