15-mar26

15-mar26 - • If a subtask doesn’t work, your solution...

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

View Full Document Right Arrow Icon
1 COMP 110 Designing and Overloading Methods Tabitha Peck M.S. March 26, 2008 MWF 3-3:50 pm Philips 367
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Announcements
Background image of page 2
3 Questions?
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Today in COMP 110 Math Methods Designing Methods Overloading Methods
Background image of page 4
5 Math Methods abs(double n), returns double ceil(float n), returns double floor(double n), returns double max(int n1, int n2), returns int min(float n1, float n2), returns float round(float n), returns int
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 abs(double n) public static double abs(double n) { if ( n < 0 ) return ( n * -1 ); else return n; }
Background image of page 6
7 ceil(float n) public static double ceil(float n) { return (double) ((int) n + 1); }
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 min(float n1, float n2) public static float min(float n1, float n2) { if ( n1 < n2 ) return n1; else return n2;  }
Background image of page 8
9 Design How would you design a video game?
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Top-Down Design Divide and Conquer Big Problem Break problem into smaller subtasks Break big subtasks into smaller subtasks Solve subtasks to solve big problem
Background image of page 10
11 Testing Subtasks = Methods
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

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

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

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

View Full DocumentRight Arrow Icon
Background image of page 16
Background image of page 17
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • If a subtask doesn’t work, your solution isn’t right • Test EVERY method you write 12 Driver programs • Simple program (for only you) • Call methods with different inputs – Positive, negative, zero – True and false – Strings, characters 13 Bottom-Up Testing drawFace setMouth drawMouth setEyeColor drawEyes setNoseSize drawNose Smiley 14 Driver Program • setMouth(true); • setMouth(false); • setNoseSize(-3); • setNoseSize(2); • setNoseSize(10); 15 Overloading • Using the same method name for two or more methods within the same class • Parameter lists are different – average(double n1, double n2) – average(double n1, double n2, double n3) • Java knows what to use based on the number and types of the arguments 16 Overloading • Change number of arguments • Change argument types • Cannot change only return type 17 Friday • Lab 6...
View Full Document

This note was uploaded on 02/02/2009 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Page1 / 17

15-mar26 - • If a subtask doesn’t work, your solution...

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

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