Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Week 9 - Friday.  What did we talk about last time?  Static method practice  Finished the Game of Life."— Presentation transcript:

1 Week 9 - Friday

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

3

4

5

6  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; }

7  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; }

8  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!

9

10  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

11  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

12  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)

13

14

15  Classes and objects

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


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

Similar presentations


Ads by Google