Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS-0401 INTERMEDIATE PROGRAMMING USING JAVA

Similar presentations


Presentation on theme: "CS-0401 INTERMEDIATE PROGRAMMING USING JAVA"— Presentation transcript:

1 CS-0401 INTERMEDIATE PROGRAMMING USING JAVA Prof. Dr. Paulo Brasko Ferreira Fall 2014

2 Chapter 5 Methods

3 Chapter 5 Presentation Outline
Introduction to Methods Passing Arguments to a Method More About Local Variables Returning a Value from a Method Problem Solving with Methods This class will be mostly hands on, using NetBeans and the PC projector

4 Introduction to Methods

5 Introduction to Methods
What is best for my company? Having a single person to handle all the tasks? Having a team of specialized persons in each area?

6 Introduction to Methods
What is best for my program? To have a single main() method that handles all code tasks To have many methods, each one handling a specific code task

7 Developing a program that finds the roots of a quadratic equation

8 Quadratic Equation Solver
Requirements: Input: - via command line (e.g., “java myProgram 2 3 4”) - user must provide three real numbers a, b, and c Output: - the roots of the about equation, i.e., the values of x that makes the above equation equals to zero

9 Discriminants vs Parabola Types
Quadratic Formula Discriminants vs Parabola Types

10 Implementing the code QuadraticEquationSolver: all functionality inside the main() method QuadraticEquationSolver2: splitting the functionality in many methods, which are called by the main() method

11 Main Points to Talk About
Method names (e.g., calculateTaxes()) Method modifiers (e.g., private static) Private, public, protected, static, final Method input arguments Void, list of arguments Method returning values Void, a single output type Calling methods With and without input arguments (primitive data are passed by value; objects are passed by reference) With and without returning type Documenting methods Variable scopes Throwing Exceptions

12 That’s an order Soldier!
Essential Reading It is essential for you to read the supplemental power point presentation called CSO_Gaddis_Java_Chapter5.ppt That’s an order Soldier!

13 That’s the End of Chapter 5

14 Any Questions?


Download ppt "CS-0401 INTERMEDIATE PROGRAMMING USING JAVA"

Similar presentations


Ads by Google