METHODS AGAIN - why methods? 1) modularity - group together some statements that do something useful - goal to reuse them 2) interact with objects - want object to worry about functionality, so that as object user, we don't have to - methods make objects do things - get information from them Example: - no params, no return values - have an object remember something for you /* We're playing Alpha Centauri... we have to keep track of how many turns have passed */ void passTurn() // body GameTime acTurns = new GameTime(); // this will happen on a regular basis acTurns.passTurn(); Example: - params only - make an object interact with your application user /* increase the brightness of the screen by degree note that brightness is on a saturating scale of 0 to 100 */ void brighten(int degree) // body Background bg = new Background(); ... // user's wearing sunglasses bg.brighten(100); Example: - return value only - get some information that the object's been remembering for you, when you actually need it /* How many coins does Mario have? */ int getNumCoins() MarioPoint mp = new MarioPoint(); // User pressed pause, need to display number of coins displayCoins(mp.getNumCoins()); Example: - params and return value - calculate something, but make this dynamic /* Calculate least common denominator */ int lcd(int a, int b) // maybe you want to build a math program Scanner stdin = new Scanner(System.in); System.out.println("First int?"); int i1 = in.nextInt(); System.out.println("Second int?"); int i2 = in.nextInt(); System.out.println("lcd is: " + lcd(i1, i2) );