انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

methods , deep look

Share |
الكلية كلية الهندسة/المسيب     القسم هندسة الطاقة     المرحلة 2
أستاذ المادة محمد علي محمد الشريفي       25/10/2012 07:58:32
Object Oriented Methods : Deeper Look Lecture Three
1
Experience has shown that the best way to develop and maintain a large
program is to construct it from small, simple pieces, or modules. This technique is
called divide and conquer. Methods, which we introduced in Last lectures, help you
modularize programs. Here , we study methods in more depth. We emphasize how
to declare and use methods to facilitate the design, implementation, operation and
maintenance of large programs.
Methods (called functions or procedures in some languages) help you
modularize a program by separating its tasks into self-contained units. You’ve
declared methods in every program you’ve written. The statements in the method
bodies are written only once, are hidden from other methods and can be reused from
several locations in a program. One motivation for modularizing a program into
methods is the divide-and-conquer approach, which makes program development
more manageable by constructing programs from small, simple pieces. Another is
software reusability sing existing methods as building blocks to create new
programs. Often, you can create programs mostly from standardized methods rather
than by building customized code. For example, in earlier programs, we did not
define how to read data from the keyboard Java provides these capabilities in the
methods of class Scanner. A third motivation is to avoid repeating code. Dividing a
program into meaningful methods makes the program easier to debug and maintain.
Static methods and Math Class:
We use various Math class methods here to present the concept of static
methods. Class Math provides a collection of methods that enable you to perform
common mathematical calculations. For example, you can calculate the square root
of 900.0 with the static method call.
Math.sqrt( 900.0 )
University of Babylon
Collage of Computer
Assistant Lecturer : Wadhah
R. Baiee
Exercise :
Build your own MyMath class with many
common mathematical methods without using
default Java Math class and its methods.
Ob
2
Decla
Me
We no
6.3 us
double
then re
41) to
method
return
bject Orien
aring Me
ethods ofte
ow conside
es a meth
e values. I
ead them f
determin
d maximu
value to lo
nted
ethods w
en require
er how to
hod called
In main, l
from the u
ne the larg
um return
ocal variab
Metho
with Mult
e more tha
write you
d maximu
lines 14–1
user. Line
gest of th
ns the resu
ble result.
ods : Deep
tiple Par
an one piec
ur own me
um to det
18 prompt
21 calls m
he three v
ult to line
. Then line
per Look
rameters
ce of infor
ethods wit
ermine an
t the user
method ma
values it r
e 21, the
e 24 outpu
Le
s
rmation to
th multiple
nd return
to enter t
aximum (d
receives a
program
uts the max
ecture Thr
o perform
e paramet
the large
three dou
declared i
as argume
assigns m
aximum va
ree
their task
ters. Figur
est of thre
uble value
n lines 28
ents. Whe
maximum’
alue.
s.
re
ee
s,
8–
en
’s
Ob
3
Imple
Th
calls to
bject Orien
Notes
? Metho
referen
? Variab
more
values
? Declar
x, floa
param
ementing
he entire b
o Math.m
r
nted
:
ods can re
nce to an
bles shoul
than one
s between
ring meth
at y is a s
meter list.
g Metho
body of ou
max, as fol
return
Metho
eturn at m
object tha
ld be decl
method o
calls to th
od parame
syntax err
d maxim
ur maximu
llows:
Math.ma
ods : Deep
most one v
at contains
lared as fi
of the cla
he class’s
eters of th
ror a type
mumby R
um metho
ax( x,
per Look
value, but
s many val
ields only
ss or if th
methods.
he same typ
e is requir
Reusing
od could a
Math.m
Le
the return
lues.
if they’re
he program
pe as float
red for ea
Method
also be im
max( y,
ecture Thr
ned value
e required
am should
at x, y inste
ach param
d Math.m
mplemente
z ) );
ree
could be
d for use i
d save the
ead of floa
meter in th
max
d with tw
a
in
ir
at
he
wo

المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
الرجوع الى لوحة التحكم