lecture10 - Administrative Issues Methods Lecture 10...

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

View Full Document Right Arrow Icon
Methods Lecture 10 Administrative Issues • Ongoing – Program 2 due tomorrow (June 4) – HW 2 due Thursday (June 5) • Coming Soon… – Midterm review session on Thursday – MIDTERM EXAM: FRIDAY JUNE 6 public class PlayingCard { // Instance variables private String suit; private byte value; // Constructor public PlayingCard( byte newValue, String newSuit) { suit = newSuit; value = newValue; } // Returns a string representation of the card public String toString() { return value + " of " + suit; } } PlayingCard Class I left off the visibility modifier in the code I handed out. The visibility defaults to public if not specified. From Yesterday… • Classes as “blueprints” for objects • Designing Classes – Nouns Data (Variables and Constants) – Verbs Methods • Anatomy of a class public class MyClass { ... } More From Yesterday… • Instance variables vs. Method Variables – Variable Scope •UML D i ag r am s – Class Diagrams – Object Diagrams • Visibility
Background image of page 1

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

View Full Document Right Arrow Icon
Method Control Flow main() method1() helpMethod() Class 1 Class 2 obj.method1() helpMethod() Anatomy of a Method • Just like variables, methods are declared • Declaration specifies the following – Visibility – Return type – Method name – Input parameters – Method body Example Declaration public int getMinimum( int val1, int val2) { int minValue; if (val1 < val2) minValue = val1; else minValue = val2; return minValue; } Visibility public int getMinimum( int val1, int val2) { int minValue; if (val1 < val2) minValue = val1; else minValue = val2; return minValue; } Return Type public int getMinimum( int val1, int val2) { int minValue; if (val1 < val2) minValue = val1; else minValue = val2; return minValue; } Method Name public int getMinimum( int val1, int val2) { int minValue; if (val1 < val2) minValue = val1; else minValue = val2; return minValue; }
Background image of page 2
Parameters public int getMinimum( int val1, int val2) { int minValue; if (val1 < val2) minValue = val1; else minValue = val2; return minValue; } Method Body public int getMinimum(
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 7

lecture10 - Administrative Issues Methods Lecture 10...

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

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