Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with.

Slides:



Advertisements
Similar presentations
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Advertisements

Methods Java 5.1 A quick overview of methods
Chapter Five Functions
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Functions. COMP104 Functions / Slide 2 Introduction to Functions * A complex problem is often easier to solve by dividing it into several smaller parts,
Modular Programming With Functions
Building Java Programs
Computer Programming w/ Eng. Applications
Return values.
Lecture 15.1 Static Methods and Variables. © 2006 Pearson Addison-Wesley. All rights reserved Static Methods In Java it is possible to declare.
Lab 8 User Defined Function.
Chapter 4 Function By C. Shing ITEC Dept Radford University.
1 Programming Languages and Paradigms Lisp Programming.
Pemrograman Dasar - Data Types1 OPERATOR. Pemrograman Dasar - Data Types2 Arithmetic operator  + - * /  / operator denotes integer division if both.
BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 3: Expressions and Interactivity.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
1 Chapter 7 User-Defined Methods Java Programming from Thomson Course Tech, adopted by kcluk.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 3: Expressions and Interactivity.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
12-2 Know how if and switch C statements control the sequence of execution of statements. Be able to use relational and logical operators in the conditional.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Expressions and Interactivity Chapter 3. 2 The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Often.
10/25: Methods & templates Return to concepts: methods Math class methods 1 st Program of the day About DrawLine.java modifications Method definitions.
Chapter 2: Objects and Primitive Data Classes and Objects String, Random, Math, NumberFormat, DecimalFormat and Wrapper Classes.
Chapter 3 Expressions and Interactivity Department of Computer Science Missouri State Univeristy.
Copyright © 2012 Pearson Education, Inc. Chapter 3: Expressions and Interactivity.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
1 Arrays An array is a collection of data values, all of which have the same type. The size of the array is fixed at creation. To refer to specific values.
ROUND 1 Name a method associated with class String 1.) 15 compareTo() 26 indexOf() 34 length() 2.) 3.) 4.) 3 toUpper() 7 substring() 11 charAt() 5.)
CMSC 1041 Functions II Functions that return a value.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Functions & Libraries. Introduction Functions – Modules of code Uses – Abstraction Build complex tasks with simpler ones Don't worry about details at.
Calculations Chapter Twelve. More serious than Chapter Four Page 199 some sizes (in bytes) of various primititive types: Do Not Memorize typeSize(bits)Approx.
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
CSCE 121: Introduction to Program Design and Concepts, Honors J. Michael Moore Spring 2015 Set 14: Plotting Functions and Data 1.
Basics and arrays Operators:  Arithmetic: +, -, *, /, %  Relational:, >=, ==, !=  Logical: &&, ||, ! Primitive data types Byte(8), short(16), int(32),
10/25: Methods & templates Return to concepts: methods Math class methods Program of the day.
Expressions and Interactivity. 3.1 The cin Object.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.
29 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Outline Creating Objects The String Class Packages Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
CSCI 1100/1202 January 23, Class Methods Some methods can be invoked through the class name, instead of through an object of the class These methods.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 3: Expressions and Interactivity.
Week 7 : String and photo processing. Today’s Tasks  Practice list and string  Convert Decimal to any radix base number  Between Binary and Hexadecimal.
CIS Intro to JAVA Lecture Notes Set 5 26-May-05.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Library Functions. CSCE 1062 Outline  cmath class library functions {section 3.2}  iomanip class library functions {section 8.5}  string class library.
1 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used as a type to declare an object reference.
CSE 110: Programming Language I Afroza Sultana UB 1230.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Lecture 3 Expressions, Type Conversion, Math and String
Chapter 7 User-Defined Methods.
Value-Returning Functions
Functions, Part 2 of 2 Topics Functions That Return a Value
Chapter 3: Expressions and Interactivity.
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Formatted and Unformatted Input/Output Functions
Expressions and Interactivity
Functions, Part 2 of 3 Topics Functions That Return a Value
Arrays.
Math class services (functions)
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with type of variables or literals as parameters Example: cos can only be passed a double

Formatting numbers Create an instances of class DecimalFormat (supply a desired pattern call method ‘format’) – int i = 123; –DecimalFormat formatter = new DecimalFormat (“###”); – textField.setText(formatter.format(i)); –// gives 123 in textField

DecimalFormat (“0000”); … Produces 0123// given int i = 123 int i = ; … (“###,##); produces 123,456 double i= 12.34; … (“###.##); … Produces double number = ; … (“0.###E0”) Produces 123E7 double money = 12.34; …(“$###.##”) Produces $12.34

Chart page 211 shows types of data sample values, patterns, formatted strings Characters: # 0, E $ all possible Insert digits or specified characters

“Money” page 212 Calculates compound interest. User enters integer amount and interest rate, program calculates interest over a period of year. Class “Interest” page Case Study “Iteration” loops that search for a solution until found to sufficient accuracy.

The sin method page 216 sin method returns the result of the absolute value of parameter x.

Graphics pages y = ax 3 + bx 2 + cx + d a,b,c and d input via slider Output scaled to fit within a panel 200 x 200 pixels ( -5.0 to +5.0) One unit x or y is 20 pixels Program calculates x value from x pixel value, y value, the value of the function y pixel value from the y value

Exceptions Overflow of ints (how to handel exceptions see chapter 16 for detail) Avoid exceptions by checking for them – if ( length > 1000 ) { answerTextField.setText (“value too large”);