{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Class 21 - Methods continued 1 Goals for Today n n Build a...

Info icon This preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
Methods, continued 1
Image of page 1

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

View Full Document Right Arrow Icon
Goals for Today n Build a method library n Distinguish between class and instance methods 2 MGMT 29000
Image of page 2
Method Libraries n Repositories for related methods n Example: Math class n Section objective: build two method libraries 3 MGMT 29000
Image of page 3

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

View Full Document Right Arrow Icon
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 4 MGMT 29000
Image of page 4
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 5 MGMT 29000
Image of page 5

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

View Full Document Right Arrow Icon
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 MGMT 29000 6
Image of page 6
Program Design (continued) MGMT 29000 7
Image of page 7

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

View Full Document Right Arrow Icon
Program Design (continued) MGMT 29000 8
Image of page 8
Program Design (continued) MGMT 29000 9
Image of page 9

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

View Full Document Right Arrow Icon
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) MGMT 29000 10
Image of page 10
Program Implementation (continued) MGMT 29000 11
Image of page 11

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

View Full Document Right Arrow Icon
Program Implementation (continued) MGMT 29000 12
Image of page 12
Program Implementation (continued) MGMT 29000 13
Image of page 13

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

View Full Document Right Arrow Icon
Unit Testing n The sole purpose of a test class ¨ Ensure that methods in the program or library work n How to implement unit testing ¨
Image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern