Using Built In Objects Kevin Harville.

Slides:



Advertisements
Similar presentations
Copyright 2011 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2,
Advertisements

Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return; double ; System.out.printf reading: 3.2, 3.5, 4.4 videos: Ch.
1 Chapter 5 Methods. 2 Introducing Methods A method is a collection of statements that are grouped together to perform an operation.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return; double ; System.out.printf reading: 3.2, 3.5, 4.4 videos: Ch.
Topic 10 return values, Math methods Based on slides bu Marty Stepp and Stuart Reges from " Thinking like a computer.
Computers and Scientific Thinking David Reed, Creighton University Functions and Randomness 1.
1 CS101 Introduction to Computing Lecture 35 Mathematical Methods (Web Development Lecture 12)
Lesson 14.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
JavaScript Part 2 – Page 1 of 35CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: JavaScript Part 2.
Topic 4 Objects CMPS 211 JavaScript. 2 Goals and Objectives Goals Goals Understand JavaScript objects, how to create and use your own objects, how to.
Java Basics. Java High-level language  More readable for humans  Need to be translated to machine language for execution Compilers  CPU-independent.
Chapter 4: Fundamentals of JavaScript 4.1 Capabilities 4.2 Essential Terminology 4.3 Structure of JavaScript Code 4.4 Data and Objects 4.5 Tokens, Operators,
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 4 Mathematical Functions, Characters,
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
Objects.  Java Script is an OOP Language  So it allows you to make your own objects and make your own variable types  I will not be going over how.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 4 part 3 GEORGE KOUTSOGIANNAKIS.
Chapter 5: Methods 1. Objectives To declare methods, invoke methods, and pass arguments to a method (§ ). To use method overloading and know ambiguous.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Method Abstraction You can.
Java Program Components Java Keywords - Java has special keywords that have meaning in Java. - You have already seen a fair amount of keywords. Examples.
Copyright 2011 by Pearson Education Building Java Programs Chapter 3 Lecture 7: Return values, Math, and double reading: 3.2,
M. Taimoor Khan Javascript Objects  Every data-type defined in Javascript is an object  It has a class definition for.
Building Java Programs Chapter 3 Parameters and Objects Copyright (c) Pearson All rights reserved.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
Numbers © Copyright 2014, Fred McClurg All Rights Reserved.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 4 Methods Chapter.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 5 JavaScript.
1 Java Library Lecture 9 by Dr. Norazah Yusof. 2 Java Library Java has pre-defined classes that consist of the basic language classes in Java (organized.
XP Tutorial 2 New Perspectives on JavaScript, Comprehensive1 Working with Operators and Expressions Creating a New Year’s Day Countdown Clock.
Math Class Mrs. C. Furman September 2, Math frequently used methods NameUse floor()rounds down ceil()rounds up pow(x,y)returns x to the power of.
Hazırlayan:Emin BORANDAĞ 2/17/ Numerik Değerler Kullanımı Integers are considered accurate up to 15 digits. Try it function myFunction() { var x.
Chapter 9: Control Statements II CIS 275—Web Application Development for Business I.
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
1 Objects In JavaScript. 2 Types of Object in JavaScript Built-in objects User Defined Objects Browser Object Document Object Model.
Copyright 2011 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2,
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
Lecture 5: java.lang.Math, java.lang.String and Characters Michael Hsu CSULA.
CSE 110: Programming Language I Afroza Sultana UB 1230.
Chapter 4 Mathematical Functions, Characters, and Strings 1.
Chapter 4 Mathematical Functions, Characters, and Strings
Math class Random() method Floor method Top-level parseInt function
Lecture 6: While Loops and the Math Class
Math Class Your favorite class!.
Building Java Programs
Building Java Programs
Building Java Programs
Chapter 4 Mathematical Functions, Characters, and Strings
Building Java Programs
Building Java Programs
JavaScript: Functions
SEEM4570 Tutorial 05: JavaScript as OOP
Java Script.
Chapter 3 Methods.
Chapter 4: Mathematical Functions, Characters, and Strings
JavaScript Basics Stephen Delaney
Java's Math class Method name Description Math.abs(value)
Building Java Programs
Java Basics.
Chapter 5 Methods.
Using Objects Kevin Harville.
Objects An object is a collection of data types as well as functions in one package The various data types called properties and functions called methods.
Building Java Programs
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Building Java Programs
Murach's JavaScript and jQuery (3rd Ed.)
Chapter 5 JavaScript Numbers and Expressions
Ch 5 : Mathematical Functions, Characters, and Strings
Presentation transcript:

Using Built In Objects Kevin Harville

Date() instantiation options: birthday = new Date(); //returns now birthday = new Date("June 20, 2001 08:00:00"); birthday = new Date(6, 20, 2001); birthday = new Date(6, 20, 2001, 8, 0, 0); Source: Sams Teach Yourself JavaScript in 24 Hours.

Setting a Date object myDay.setDate(4); myDay.setMonth(0); myDay.setYear(99); //use setFullYear myDay.setFullYear(1999); myDay.setHours(23); myDay.setMinutes(30); myDay.setSeconds(0);

Getting Date Object Info alert(myDay.getDate()); document.write(myDay.getMonth()); myYear = myDay.getYear(); //use getFullYear myDay.getFullYear(); myDay.getHours(); myDay.getMinutes(); myDay.getSeconds();

Math Math is encapsulated in an object format. There are things Math can do - methods, and properties of math, such as PI. Math properties never change Therefore, a function such as raising a number to a power is done via a Math method: myVar = Math.pow ( 2, 4 ); Don't make your own math object. Use the object, Math, javascript provides.

Math Methods Math.random() returns a random number from zero up to, but not including, one.

Math Methods - Rounding Math.round( myVar ) Math.floor( myVar ) Math.ceil( myVar )

Math Methods - Trigonometry Math.acos(x) Math.asin(x) Math.atan(x) Math.cos(x) Math.sin(x) Math.tan(x) IMPORTANT - THESE CALCULATIONS ARE DONE IN RADIANS. A SIMPLE BUT NECESSARY CONVERSION FROM RADIANS TO DEGREES NEEDED.

Math Minimum / Maximum Math.max ( valA, valB ) Math.min ( valA, valB)

Math Powers and Roots Math.pow ( num, pwr ) Math.sqrt ( 25 )

Other Math Methods Other Math methods exist. Consult your reference materials when doing higher math.

Math Properties Math.E Math.PI Math.LN2 Math.LN10 Math.LOG2E Math.SQRT1_2 Math.SQRT2 The Math object's properties are Math constants. The only Math property I want you to know for this class is Math.PI

Browser Objects

Document Object Model window location document history anchors [ ] links [ ] forms [ ] images [ ] elements [ ]

Things you can do with DOM Refer to document properties Clear a document Refer to and modify specific anchors and links. Move to and refer to previous and next pages. Move to a specific new page

Things you can do... You can do much more. The details in this chapter were only briefly covered. Read Chapters 9 and 10. All this is done by using the Document Object Model and object-oriented programming.