agenda

12
Agenda • Remarks about last homeworks • Methods(functions) • Class methods(static methods) • Presentations topic • homework

Upload: hestia

Post on 05-Jan-2016

24 views

Category:

Documents


0 download

DESCRIPTION

Agenda. Remarks about last homeworks Methods(functions) Class methods(static methods) Presentations topic homework. FlowChart for GradeSystem C onverter. The GradeSystemConverter algorithm: 1. Prompt the user for a number. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Agenda

Agenda

• Remarks about last homeworks• Methods(functions)• Class methods(static methods)• Presentations topic• homework

Page 2: Agenda

FlowChart for GradeSystemConverter

The GradeSystemConverter algorithm:1. Prompt the user for a number.2. Determine the letter grade that corresponds to the entered numeric grade and display the result. 3. Repeat steps 1 and 2 until the user chooses to quit.

Page 3: Agenda

FlowChart for GradeSystemConverter

Get numeric grade from user

Start

End

Determine and display letter grade

Page 4: Agenda

Procedural programming1. Gather ingredients: 1c flour, 1c

butter, 1c sugar, 2 eggs2. Preheat oven to 350 degrees3. Beat eggs and butter4. Add flour and sugar5. Mix6. Bake 10 minutes

Page 5: Agenda

Methods

• Procedural programming – step by step instructions; linear order of instructions

• A function is a ``black box'' that we've locked part of our program into, it performs some well-defined task, which will be useful to other parts of the program.

• Idea of reuse.

Page 6: Agenda

• A method consists of a declaration and a body.

• Method declaration includes: access level, return type, name, and parameters, if any.

• The method body contains the statements that implement the method.

<access level> <return type> <method names> (<parameter>){…}

Writing methods

Page 7: Agenda

Example

public static void main(String[] args)

Smiling face applicatin example public void printSmileyface() { }

Page 8: Agenda

Methods signature

• access level: public, private• Return type: void, int, double, char..any

variable types• Method names: defined by yourselves• Parameters: can have 0 or more than 1

Page 9: Agenda

Example• Transfer the two applications into functions:

1. Print a smiling face – no parameters2. RectanglePerimeter application that

calculates and displays the perimeter of a rectangle with width 4 and length 13 –

can be modified by passing parameters ofwidth and length.

3. Modify the GradeConversionSystem, writea function which takes a number grade and returns a letter grade

Page 10: Agenda

Methods(functions)

• Has its own block of codes, enclosed by curley braces

• Called from main() by its method names

Page 11: Agenda

Static methods• BPJ lesson 20; Barron’s chapter 2• Static methods are sometimes called class

methods.• The difference between static and no-static

methods: we are accessing them at the class level rather than the object level.

• Math class vs Random classMath.sqrt(4.0);Random.nextInput(); => wrong

Page 12: Agenda

Homework• Modify the program of printing a star triangle

upside down using method. • Write a public method, return type void,

parameters 2, one for length, one for symbol.• The method uses one for loop to loop to the

length,print the symbol.• Call the method 6 times to produce the same

drawing as last homework