Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)

Similar presentations


Presentation on theme: "Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)"— Presentation transcript:

1 Agenda Warmup Lesson 2.5 (Ascii, Method Overloading) Independent Practice (2.5 Assignments) Time Permitting: Lesson 2.6 (Constructors, Encapsulation, etc) Closure Activity Students will be able to: Understand what Ascii code is, and how to convert to it from a char variable Understand what method overloading is, and when it should be used Write an overwritten method See how today's lesson fits into the unit and the course as a whole

2 Warmup Write the first line only of the following methods: Result?
Accepts an int parameter, returns its absolute value Accepts no parameters, displays the word “hi” Accepts a String parameter, returns true if it’s longer than 5 chars, false otherwise Accepts 3 double parameters, displays their sum Result? for (int x=0; x<20; x++) int y=0; System.out.println(y); 3) When an instance variable (or method) is declared with either “private” or “public”, what is the technical name for that word? Don’t look here.

3 ASCII / Unicode In Java, each character - letters, symbols, etc., has a number value associated with it. This is called its Ascii value or Unicode value. See ascii table (in folder) To convert a char into its ascii value, type cast it into an integer, or save it in an integer variable The reverse can be done to convert an integer into its equivalent character. Ascii can be used in many different ways. One was is to error check that the user is entering a valid character. Demo: Ascii

4 Method Overloading A method’s signature is its name and list of parameters – in other words, the first line of a method (except for the visibility modifier and the return type). Method Overloading is when you use two methods with the same name, but different lists of parameters, in the same class. This is valid, as long as the parameters are different, in 1 of 3 possible ways: Type Number Order

5 Why overload a method? Because sometimes you need to perform similar operations on different types of data Demo: OverloadClass, OverloadClient A method’s return type is not part of its signature, so if 2 methods are only different in their return types, then Java won’t know the difference. This will cause an error. The same rule applies to the visibility modifier, which is not part of a method signature.

6 Assignments P. 242 # 13-18 Use one class (P242Class) and one client (P242Client) for these assignments. (#13: “floating point” is another name for a double) (#18: hint: the if-statement should NOT be very long) Create your own method (in P242Class). Make it interesting. Then overload that method. Finally, call both methods from the client.


Download ppt "Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)"

Similar presentations


Ads by Google