Week 9 - Friday.  What did we talk about last time?  Static method practice  Finished the Game of Life.

Slides:



Advertisements
Similar presentations
Functions Prototypes, parameter passing, return values, activation frams.
Advertisements

CSE 251 Dr. Charles B. Owen Programming in C1 Functions.
Building Java Programs
1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Return values.
Recursion CS 367 – Introduction to Data Structures.
Building Java Programs
Week 5 - Friday.  What did we talk about last time?  Repetition  while loops.
Chapter 5 Functions.
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 Chapter 18 Recursion Dale/Weems/Headington. 2 Chapter 18 Topics l Meaning of Recursion l Base Case and General Case in Recursive Function Definitions.
Copyright 2008 by Pearson Education 1 Midterm announcements Next week on Friday May 8 Must bring an ID Open book, open notes, closed electronics Must attend.
Options for User Input Options for getting information from the user –Write event-driven code Con: requires a significant amount of new code to set-up.
1 Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1, 5.6.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
Week 10 - Monday.  What did we talk about last time?  More permutations  Addition rule  Inclusion and exclusion.
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Section 1.7 Using Variables and Formulas. 1.7 Lecture Guide: Using Variables and Formulas Objective 1: Evaluate an algebraic expression for specific values.
Instructions To use this template: –for each slide write the correct answer on the orange bar first –choose which option (A,B,C or D) and make sure you.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Some Uses of Probability Randomized algorithms –for CS in general –for games and robotics in particular Testing Simulation Solving probabilistic problems.
1 Logical Assertions. 2 Logical assertions assertion: A statement that is either true or false. Examples: –Java was created in –The sky is purple.
Programming Principles Chapter 1. Objectives Discuss the program design process. Introduce the Game of Life. Discuss object oriented design. – Information.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
Discussion 4. Labs public MyPoint(double xInit, double yInit ) { MyPoint p = new MyPoint(0, 0); } ClassProblem.java recursive java.lang.StackOverflowError.
Random numbers. 2 The Random class A Random object generates pseudo-random numbers. –Class Random is found in the java.util package. import java.util.*;
A First Book of ANSI C, Fourth Edition1 Functions for Modularity 04/24/15.
1 Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1, 5.6.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
Modular Programming ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
Week 9 - Wednesday.  What did we talk about last time?  2D arrays  Queen attacking pawn example  Started Game of Life.
6.5: RELATED RATES OBJECTIVE: TO USE IMPLICIT DIFFERENTIATION TO RELATE THE RATES IN WHICH 2 THINGS ARE CHANGING, BOTH WITH RESPECT TO TIME.
CS1101: Programming Methodology
Chapter 5 Methods 1. Motivations Method : groups statements that perform a function.  Level of abstraction (black box)  Code Reuse – no need to reinvent.
1 Scope Lifetime Functions (the Sequel) Chapter 8.
C# Programming Methods.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Conditionals.
Announcements. Practice questions, with and without solutions will be uploaded by Friday 5 th November, make sure to check them before the weekend \\netstorage\Subjects\ITCA-b\Exam.
Week 10 - Monday.  What did we talk about last time?  Combinations  Binomial theorem.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
1 Building Java Programs Chapter 5 Lecture 11: Random Numbers reading: 5.1, 5.6.
Shlomo Hershkop Basics overview. Shlomo Hershkop Basic Review - Overview Practice coding Practice coding finger guessing game finger guessing.
Lecture 12: Dividing Up Work. Why Using Functions Divide-and-conquer making large program development more manageable. Software reusability Use existing.
Class 2 – Recursion on Lists
Building Java Programs
Building Java Programs
Suppose we want to print out the word MISSISSIPPI in big letters.
Welcome to Jeopardy! Retrieved from Hillgrove High School, Cobb County Schools, Georgia.
Building Java Programs
Notes Over Pythagorean Theorem
Value returning Functions
Quiz Review.
Logical assertions assertion: A statement that is either true or false. Examples: Java was created in The sky is purple. 23 is a prime number. 10.
Building Java Programs
CS2011 Introduction to Programming I Methods (II)
Building Java Programs
Beat the Computer Drill
Welcome to Jeopardy!.
CONVERSE of the Pythagorean Theorem If a2 + b2 = c2, then the
Announcements Project- Make sure you me the project report
Lab6 PROGRAMMING 1 metheds chapter5.
Unit-1 Introduction to Java
Building Java Programs
Maximum and Minimum Points
Presentation transcript:

Week 9 - Friday

 What did we talk about last time?  Static method practice  Finished the Game of Life

 By now, everyone should be familiar with the simple method that returns the maximum of two values: public static int max( int a, int b ) { if( a > b ) return a; else return b; } public static int max( int a, int b ) { if( a > b ) return a; else return b; }

 What if we wanted to have a method with the same name that took three arguments and gave the maximum of them? public static int max( int a, int b, int c ) { if( a > b && a > c ) return a; else if( b > a && b > c ) return b; else return c; } public static int max( int a, int b, int c ) { if( a > b && a > c ) return a; else if( b > a && b > c ) return b; else return c; }

 Yes!  All that we need is the parameters to be different so that the compiler can figure out which function to use  The number or types (or both) of the parameters must be different  A different return type is not enough!

 Recall that C = (5/9)(F – 32)  C is the temperature in degrees Celsius  F is the temperature in degrees Fahrenheit  Write a method that takes a double value in Fahrenheit and returns the answer in Celsius

 Write a method with the following header: public static void rightTriangle( double a, double b, double c)  This method uses the Pythagorean equation (a 2 + b 2 = c 2 ) to find the lengths of the sides of a right triangle  This method will compute the value for a, b, or c if the other two values are known  A user calls this method with the unknown value set to be zero  If no values are zero, check to make sure that the answer is correct  If exactly one value is zero, compute it, and print the answer  If two or more values are zero, print that it is impossible to determine the lengths

 Write a complete program that simulates betting on a roulette wheel  You start with $1000 in your bank  Each turn, you bet a dollar amount and either red ( r ) or black ( b )  Include a method with the following prototype:  public static boolean spin(char guess)  This method randomly picks a number between 1 and 38 (where 37 is 0 and 38 is 00) and determines whether or not your guess (r or b) was correct  Remember, there are 38 numbers on an American roulette wheel:  1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36 are red  2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35 are black  0 and 00 are green (neither red nor black)

 Classes and objects

 Read Chapter 9 of the textbook  Keep working on Project 3  Due tonight before midnight