Class 19 - Methods, continued Matthew Hashim Click to edit...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
12/4/09 Click to edit Master subtitle style Methods, continued Matthew Hashim 10/29/2009 11
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Goals for Today n Build a method library n Distinguish between class and instance methods 22
Background image of page 2
MGMT 290D 12/4/09 Method Libraries n Repositories for related methods n Example: Math class n Section objective: build two method libraries 33
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Problem Description: Ballooning a Bedroom n Problem context ¨ Your friend who plays practical jokes is away ¨ You want to play a practical joke on your friend ¨ You plan to fill your friend’s room with balloons n Question: how many balloons should you purchase n The question will be answered by a program 44
Background image of page 4
MGMT 290D 12/4/09 Program Design n The problem is concerned with volumes ¨ Find out how many balloon volumes fit in a room volume n The balloon is approximated by a sphere ¨ volumesphere = 4/3 x PI x radius3 n The room is approximated by a box ¨ volumebox = length x width x height n Another issue: whether to use large or small balloons ¨ Large balloons take long to inflate, but fewer are needed ¨ Small balloons inflate quickly, but more are needed 55
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Program Design (continued) n Essentials of the user story ¨ Query the user for the radius of the balloon ¨ Read the radius from the keyboard ¨ Compute the volume of one balloon ¨ Compute the volume of the bedroom n Note: dimensions of room are declared as constants ¨ Compute number of balloons needed to fill the bedroom ¨ Display the required number of balloons, with labels n Identify nouns and verbs to find objects and operations n Organize objects and operations into an algorithm 66
Background image of page 6
MGMT 290D 12/4/09 Program Design (continued) 77
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Program Design (continued) 88
Background image of page 8
MGMT 290D 12/4/09 Program Design (continued) 99
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Program Implementation n First decision: write methods to compute volumes ¨ Rationale: methods allow computations to be reused n Second decision: store methods in separate classes ¨ Rationale: makes the program more modular n Three classes will be used to implement the program ¨ BalloonPrank : contains the main() driver method ¨ Sphere : library containing sphere methods ¨ Box : library containing box methods n Sphere.volume() : takes one argument (radius) n Box.volume() : takes three arguments (l, w, h) 1010
Background image of page 10
MGMT 290D 12/4/09 Program Implementation (continued) 1111
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Program Implementation (continued) 1212
Background image of page 12
MGMT 290D 12/4/09 Program Implementation (continued) 1313
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

Class 19 - Methods, continued Matthew Hashim Click to edit...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online