Mat 2170 Week 6. Methods. Week 6. Mat 2170 Week 6. Jargon. Info Hiding. Math Lib. Lab 6. Exercises. Methods. Spring 2014

Similar documents
Guide to Success I. in December)

Guide to Success I. in December)

Throughout the semester: questions slides book programming review questions practice exam

Expressions in JavaScript. Jerry Cain CS 106AJ October 2, 2017

Expressions. Eric Roberts Handout #3 CSCI 121 January 30, 2019 Expressions. Grace Murray Hopper. Arithmetic Expressions.

Functions and Libraries Once upon a time...

Python Lists: Example 1: >>> items=["apple", "orange",100,25.5] >>> items[0] 'apple' >>> 3*items[:2]

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

write vs. writeln Prompting as Page Loads Today s Goals CSCI 2910 Client/Server-Side Programming Intermediate File vs. HTML Output

1001ICT Introduction To Programming Lecture Notes

Methods CSC 121 Fall 2014 Howard Rosenthal

C++ Programming Lecture 11 Functions Part I

8-1 Simple Trigonometric Equations. Objective: To solve simple Trigonometric Equations and apply them

CT 229 Java Syntax Continued

Methods CSC 121 Fall 2016 Howard Rosenthal

Methods CSC 121 Spring 2017 Howard Rosenthal

Variable and Data Type 2

Math 144 Activity #4 Connecting the unit circle to the graphs of the trig functions

Math12 Pre-Calc Review - Trig

Welcome. Please Sign-In

PreCalculus Summer Assignment

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

int: integers, no fractional part double: floating-point numbers (double precision) 1, -4, 0 0.5, , 4.3E24, 1E-14

Trigonometric ratios provide relationships between the sides and angles of a right angle triangle. The three most commonly used ratios are:

Unit 4 Graphs of Trigonometric Functions - Classwork

MEI GeoGebra Tasks for A2 Core

Goals for This Lecture:

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.

Chapter 3 - Functions

2 Unit Bridging Course Day 10

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

4. Modules and Functions

You can take the arccos of both sides to get θ by itself.

GREENWOOD PUBLIC SCHOOL DISTRICT Algebra III Pacing Guide FIRST NINE WEEKS

Programming in QBasic

Excel Spreadsheets and Graphs

Numerical Methods Lecture 1

Inverse Trigonometric Functions:

Quadratic Equations. Learning Objectives. Quadratic Function 2. where a, b, and c are real numbers and a 0

Standard Library Functions Outline

Basic Graphs of the Sine and Cosine Functions

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

: Find the values of the six trigonometric functions for θ. Special Right Triangles:

What is log a a equal to?

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 5. Playing with Data Modifiers and Math Functions Getting Controls

2.9 Linear Approximations and Differentials

static int min(int a, int b) Returns the smaller of two int values. static double pow(double a,

Dr Richard Greenaway

Intrinsic Functions Outline

Math Analysis Final Exam Review. Chapter 1 Standards

CW High School. Advanced Math A. 1.1 I can make connections between the algebraic equation or description for a function, its name, and its graph.

Math 144 Activity #2 Right Triangle Trig and the Unit Circle

2 Making Decisions. Store the value 3 in memory location y

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

Introduction to Programming

Sum and Difference Identities. Cosine Sum and Difference Identities: cos A B. does NOT equal cos A. Cosine of a Sum or Difference. cos B.

Unit 1 Quadratic Functions

Unit O Student Success Sheet (SSS) Right Triangle Trigonometry (sections 4.3, 4.8)

9 Using Equation Networks

Trigonometric Functions of Any Angle

Education Resources. This section is designed to provide examples which develop routine skills necessary for completion of this section.

Introduction to Programming

Math 144 Activity #3 Coterminal Angles and Reference Angles

AP Calculus AB. Table of Contents. Slide 1 / 180. Slide 2 / 180. Slide 3 / 180. Review Unit

Math 1330 Test 3 Review Sections , 5.1a, ; Know all formulas, properties, graphs, etc!

Chapter 7. Iteration. 7.1 Multiple assignment

Chapter 2. Outline. Simple C++ Programs

C++, How to Program. Spring 2016 CISC1600 Yanjun Li 1

The Straight Line. m is undefined. Use. Show that mab

Graphing Trig Functions - Sine & Cosine

A Quick Review of Trigonometry

MEI Casio Tasks for A2 Core

MATH STUDENT BOOK. 12th Grade Unit 4

First of all, we need to know what it means for a parameterize curve to be differentiable. FACT:

MATH EXAM 1 - SPRING 2018 SOLUTION

Algebra II: Strand 3. Quadratic Functions; Topic 2. Digging Deeper; Task 3.2.1

AP Calculus AB. Table of Contents. Slide 1 / 180. Slide 2 / 180. Slide 3 / 180. Review Unit

Amphitheater School District End Of Year Algebra II Performance Assessment Review

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017

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

>>> * *(25**0.16) *10*(25**0.16)

Dover-Sherborn High School Mathematics Curriculum Pre-Calculus Level 2/CP

Prerequisites for Math 130

Unit R Student Success Sheet (SSS) Trigonometric Identities Part 2 (section 5.4)

Angle Measure 1. Use the relationship π rad = 180 to express the following angle measures in radian measure. a) 180 b) 135 c) 270 d) 258

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

INDEX INTRODUCTION...1

CSc 110, Autumn Lecture 10: return values and math

AP Calculus Summer Review Packet

Guide to Planning Functions and Applications, Grade 11, University/College Preparation (MCF3M)

CSc 110, Spring Lecture 11: return values and math

Programming via Java Subclasses

Algebra 2 Common Core Summer Skills Packet

Methods (Deitel chapter 6)

Part Five: Trigonometry Review. Trigonometry Review

The given function is in transformational function form. 15. Write the function that represents the graph Simplify:

What did we talk about last time? Math methods boolean operations char operations

Methods (Deitel chapter 6)

Student Exploration: Quadratics in Polynomial Form

Transcription:

Spring 2014

Student Responsibilities Reading: Textbook, Chapter 5.1 5.3 Lab Attendance

Chapter Five Overview: 5.1 5.3 5.1 Quick overview of methods 5.2 Writing our own methods 5.3 Mechanics of the method calling process

Quick Overview of You ve been working with methods ever since Lab 1 and the HelloWorld program. The run() method in every program is one example. Other examples are println(), setcolor(), and getheight().

Basically a method is a sequence of statements collected together and given a name. The name makes is possible to execute the statements more easily. Instead of copying the entire list of statements, we can simply provide the method name.

Useful Terms Invoking a method (using its name) is known as calling that method. The part of a program or code that invokes a method is named the caller or calling program. The caller can pass information to a method by using arguments (the java expressions in the parentheses), e.g.: R.setFilled(true) R.setFilled((row + col) % 2 == 0) Color mycolor = Color.green; R.setColor(myColor)

When a method completes its operation, it returns to the code which invoked it (i.e., the caller). A method can pass information back to the caller by returning a single result.

Method Calls as Messages The act of calling a method is often described in terms of sending a message to an object. The method call: R.setColor(Color.RED); is regarded metaphorically as sending a message to the GRect object R telling it to change its color to red.

Receivers The object to which a message is sent is called the receiver. The general pattern for sending a message to an object is: receiver.methodname(argument list)

Information Hiding One important advantage of methods: They allow us to ignore the inner workings of complex operations. When a method is used, it is more important to know what the method does than to understand exactly how it does it. The underlying details of a method are of interest only to the programmer who implements and maintains it.

Method Interface Programmers who utilize a method are concerned about: 1. The method interface 1.1 return type 1.2 method name 1.3 order, number and type of arguments 2. Whether the method is correct. They can usually ignore the implementation altogether. The idea that callers should be insulated from the details of a method is the principle of information hiding, one of the cornerstones of software engineering.

as Tools for Programmers A method provides a service to a programmer, who is typically creating some kind of application. A programmer utilizes methods to reduce the amount of work he or she must do, and to organize the software they are writing. like readint() and println() are used to communicate with and obtain information from the user.

Method Calls as Expressions Syntactically, method calls in Java are part of the expression framework. that return a value can be used as terms in an expression, just like variables and constants. The Math class in the java.lang package defines several methods that are useful in writing mathematical expressions. that belong to the entire class are called static methods.

rary Method Calls You must include the name of the class, along with the method name, for example: Math.sqrt(). Suppose we need to compute the distance from the origin to the point (x, y), which is given by the formula: d = x 2 + y 2 We can apply the square root function by calling the method from the Math class: sqrt() double distance = Math.sqrt(x * x + y * y);

Useful in the Math Class Math.abs(x) Math.min(x, y) Math.max(x, y) Math.sqrt(x) Math.log(x) Math.exp(x) Math.pow(x, y) Returns the absolute value of x Returns the smaller of x and y Returns the larger of x and y Returns x, the square root of x Returns log e x, the natural logarithm of x Returns e x, the inverse logarithm of x Returns x y, the value of x raised to the y power

The Math Class Trig Functions Math.sin(theta) Math.cos(theta) Math.tan(theta) Math.asin(x) Math.acos(x) Math.atan(x) Returns the sine of theta, measured in radians Returns the cosine of theta Returns the tangent of theta Returns the angle whose sine is x Returns the angle whose cosine is x Returns the angle whose tangent is x

The Math Class Conversion Functions Math.toRadians(degrees) Math.toDegrees(radians) Converts an angle from degrees to radians Converts an angle from radians to degrees

Solving Quadratic Equations The standard quadratic equation is: ax 2 + bx + c = 0 The quadratic formula, to solve for the roots, is: x = b ± b 2 4ac 2a Of interest to us is the radicand, since it determines the number of solutions: b 2 4ac How many real solutions are there when the radicand is... 1. positive? 2. zero? 3. negative?

Also of Use in More messages available for GRect and GOval objects getx() gety() getwidth() getheight() move(dx, dy) returns the x component of the object s position returns the y component of the object s position returns the width of the object returns the height of the object moves the object using the displacements dx and dy

Examples Assume R is a GRect and C is a GOval: R.getX() C.getX() R.getY() C.getY() R.getWidth() R.getHeight() R.move(1.0, 1.5) R.move(dx, dy) C.getWidth() C.getHeight() C.move(1.0, 1.5) C.move(dx, dy)

Problem Solving in Class Design algorithms, then programs, to: Create a table of values for x, x, and x 2 running from x = 0 to x = 100 by 10s Create a table of values for x, sin(x), and cos(x) as x runs from 0 to 2π by π 4 increments. Solve for the n th Fibonacci number, defined by the sequence 0, 1, 1, 2, 3, 5, 8, 13... The first two terms are 0 and 1, and every subsequent term is the sum of the preceding two. Modify the previous program to display all the terms in the Fibonacci sequence that are smaller than 1,000.