1 COMP 110 Designing and Overloading Methods Tabitha Peck M.S. March 26, 2008 MWF 3-3:50 pm Philips 367.

Slides:



Advertisements
Similar presentations
COMP 110: Introduction to Programming Tyler Johnson Mar 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
CS110 Programming Language I
Computer Programming Lab 8.
Chapter 5 Methods to our madness. Review Identifiers are names used for variables, constants, methods, classes, and packages. Must start with a letter,
1 COMP 110 Inheritance Tabitha Peck M.S. April 16, 2008 MWF 3-3:50 pm Philips 367.
Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)
1 COMP 110 Static Methods and Variables Tabitha Peck M.S. March 24, 2008 MWF 3-3:50 pm Philips 367.
General Announcements Project Due Friday, 1/30 Labs start Wednesday & Thursday – Java review – Weiss 1.19, 1.20 – You may show up & hand in Workshops.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
Math class methods & User defined methods Introduction to Computers and Programming in JAVA: V
COMP 110 More Loops and Strings Tabitha Peck M.S. February 18, 2008 MWF 3-3:50 pm Philips
1 COMP 110 Arrays Tabitha Peck M.S. March 31, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Objects and References Tabitha Peck M.S. February 27, 2008 MWF 3-3:50 pm Philips
1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips
COMP 110 Designing Programs Tabitha Peck M.S. January 16, 2008 MWF 3-3:50 pm Philips
COMP 110 Primitive Types, Strings, and Console I/O Tabitha Peck M.S. January 23, 2008 MWF 3-3:50 pm Philips
COMP 110 If / Else and Case Statements Tabitha Peck M.S. February 4, 2008 MWF 3-3:50 pm Philips
COMP 110 Errors, Strings, and Review Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
Slides prepared by Rose Williams, Binghamton University Chapter 11 Recursion.
COMP 110 Branching Statements and Boolean Expressions Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
Simple Recursion. COMP104 Lecture 35 / Slide 2 Recursion: Example 0 * What does the following program do? #include using namespace std; int fac(int n){
COMP 110 Switch Statements and Loops Tabitha Peck M.S. February 6, 2008 MWF 3-3:50 pm Philips
COMP 110 Classes Tabitha Peck M.S. March 3, 2008 MWF 3-3:50 pm Philips
COMP 110 Information Hiding and Encapsulation Tabitha Peck M.S. February 25, 2008 MWF 3-3:50 pm Philips
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
© 2007 Lawrenceville Press Slide 1 Chapter 7 Top-Down Development  Problem-solving approach  Breaking a task down into smaller subtasks  First level.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
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.
METHODS Introduction to Systems Programming - COMP 1005, 1405 Instructor : Behnam Hajian
Week 6 - Wednesday.  What did we talk about last time?  Exam 1 post-mortem  Recursive running time.
Passing Other Objects Strings are called immutable which means that once a String object stores a value, it never changes –recall when we passed a message.
COMP Recursion, Searching, and Selection Yi Hong June 12, 2015.
Data Types & Operations 1 Last Edited 1/10/04CPS4: Java for Video Games Data Types.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
COMP 110 Objects and references Luv Kohli October 8, 2008 MWF 2-2:50 pm Sitterson 014.
Elementary C++. Procedural Programming Split your problem into simpler parts then solve each part separately Recognize common parts and solve them only.
Methods: functions & procedures. Top-down programming Divide-and-conquer technique Divide-and-conquer technique Problem is broken down into a series of.
Catie Welsh March 23,  Lab 6 due Friday by 1pm 2.
COMP 110 Static variables and methods Luv Kohli October 29, 2008 MWF 2-2:50 pm Sitterson 014.
A: A: double “4” A: “34” 4.
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
Week 9 - Wednesday.  What did we talk about last time?  2D arrays  Queen attacking pawn example  Started Game of Life.
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
COMP 110 Designing and overloading methods Luv Kohli November 3, 2008 MWF 2-2:50 pm Sitterson 014.
Chapter 5 Methods 1. Motivations Method : groups statements that perform a function.  Level of abstraction (black box)  Code Reuse – no need to reinvent.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Lecture 10: Object Oriented Programming Tami Meredith.
Chapter 5 Methods F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters F Pass by Value F Overloading Methods F Method Abstraction.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
4. Java language basics: Function
Methods Chapter 6.
More About Objects and Methods
Chapter 7 Top-Down Development
Java Lecture Recursion 29th feb 2005
Chapter 4 Procedural Methods.
Introduction to Robots and the Mind - Methods -
Review Operation Bingo
null, true, and false are also reserved.
Questions? Math Class Wrapper Classes Writing / Testing Methods.
CS2011 Introduction to Programming I Methods (II)
Chapter 7 Procedural Methods.
Unit-1 Introduction to Java
Agenda Types and identifiers Practice Assignment Keywords in Java
Michele Weigle - COMP 14 - Spr 04
Presentation transcript:

1 COMP 110 Designing and Overloading Methods Tabitha Peck M.S. March 26, 2008 MWF 3-3:50 pm Philips 367

2 Announcements

3 Questions?

4 Today in COMP 110 Math Methods Designing Methods Overloading Methods

5 Math Methods –abs(double n), returns double –ceil(float n), returns double –floor(double n), returns double –max(int n1, int n2), returns int –min(float n1, float n2), returns float –round(float n), returns int

6 abs(double n) public static double abs(double n) { if ( n < 0 ) return ( n * -1 ); else return n; }

7 ceil(float n) public static double ceil(float n) { return (double) ((int) n + 1); }

8 min(float n1, float n2) public static float min(float n1, float n2) { if ( n1 < n2 ) return n1; else return n2; }

9 Design How would you design a video game?

10 Top-Down Design Divide and Conquer Big Problem Break problem into smaller subtasks Break big subtasks into smaller subtasks Solve subtasks to solve big problem

11 Testing Subtasks = Methods If a subtask doesn’t work, your solution isn’t right Test EVERY method you write

12 Driver programs Simple program (for only you) Call methods with different inputs –Positive, negative, zero –True and false –Strings, characters

13 Bottom-Up Testing

14 Driver Program setMouth(true); setMouth(false); setNoseSize(-3); setNoseSize(2); setNoseSize(10);

15 Overloading Using the same method name for two or more methods within the same class Parameter lists are different –average(double n1, double n2) –average(double n1, double n2, double n3) Java knows what to use based on the number and types of the arguments

16 Overloading Change number of arguments Change argument types Cannot change only return type

17 Friday Lab 6