Compute taxes Write a story Text-to-speech Figure out chance of rolling certain number on dice Simulate dice rolls Simple game with dice Simulate a chess game Or checkers Pick out what shirt to wear today Fashion simulator Scheduler Pick classes to take Balance budget Decide whether to buy or rent a textbook for a course Search for an answer to a question online Dragon simulator :-) Dragon-fighting game (turn-based) Egg incubator Egg monitoring program Rhyme finder Elephant rider Fashion simulator Pick out what to wear today - List of pants - List of shirts - List of shoes - Have to tell what matches -- what matches are acceptable, and what are not Suppose when program starts, it already knows all about your clothes. Suppose you want it to just randomly generate a description of your clothes. Suppose you want it to decide what matches and what doesn't. If all we want is a textual description of each piece of clothing, don't need objects. Can just store strings in variables (or soon, an array!) But what if we want the program to automatically determine if clothes match. Could store the COLORS of each piece of clothing. HOw to represent color? Could use Red, Green, Blue values. Need program to decide what colors match. Could see if there are well-accepted formulas online. Could write simple formulae. Red and pink don't go together. Red and orange don't go together. No pastel with solid colors. Something like that. A few simple rules. Maybe better yet, consider things like frills & lace. Or blue-jeans with button-up shirt not so good. Fancy-ness level of things. t-shirt cannot go with khakis. Or can it? Need better idea what program will look like. Welcome to the clothing selection program. What would you like to do? 1. Pick a random selection. 2. Enter a combination 3. See current options 4. Enter the clothing combination we want What would we need to store behind the scenes? 1. Which shirt is selected 2. Which pants are selected How would we determine whether pants/shirt match? Check colors. Check style. If all good, say it's a match. Now, for the code design question. How are we going to write this? Brainstorm tasks: Accept input from user. Main menu behavior Print list of shirts Print list of pants Print list of THINGS (most generically) Compute if given pair of pants matches a given shirt Add clothing to list of clothing Remove clothing from list of clothing Create list of clothing Get random shirt Get random pair of pants Select given pair of pants Select shirt What objects are there? * pants * shirts * potential match? * List of pants * List of shirts How to organize as a program? May be lots of duplicate code between pants and shirts -- can we have a single object that represents both? (Similar behavior) "Clothing" class. Similarly, could have a "List of clothing" class. Holds up to three items, to keep things simple. Then could "add Clothing" and "remove Clothing" -- ooh , these are more actions What information does clothing class need? - Color - Fanciness (Nice that this is a class - automatically holds color & fancieness together.) But clothes themselves don't really have any behavior. Yeah, no behavior. Where to put the matching behavior? Could put it in the clothing class. this.isMatchTo(that) Then, this method could incorporate all our logic. How do we structure all those tasks we thought up earlier? Menu structure - main program Get random shirt - Clothing list class Get random pants - Clothign list class Pick pants -- main program? Clothing list class? Current match - main program Check for match - clothing class Why are we doing all of this? What methods will call other methods mainMenu ----------------------- | \ \ listClothing selectClothing checkMatch / \ compareStyles compareColors Now, the design strategies: top-down design. Start at top, work way down. How does this apply to the clothing example? Start at top -- that's main. Write the main method. Leave blank methods for the stubs. Bottom-up design. That's this.isMatchTo(that) Write this.isMatchTo(that). Test that. Then write ClothingList. Then write main. What classes do we really need? When do we have different variables that hold mostly the same thing? When do we have "objects" that have behaviors? In our case, the "user" is the one doing most things. But the user does COMPARE a shirt to a pair of pants. Or select an object. Or "main" could do this. But since the info is stored in the shirt, don't need to pass it around as much. It's an art. But there is surely some code that's better and some code that's worse. But there is also a lot of code that is just as good as another approach. [After this, I started writing the the ClothesChooser using a Top-Down approach. I started with ClothesChooser.java, and just started "using" any lower-level classes that didn't exist yet] OK... so what are my outcomes beyond the outcomes for today? - Brainstorm a list of tasks - Organize those tasks into a call tree - See "domain objects" as potential classes - See multiple instances as a opportunity to create a class - See classes as an opportunity to put related tasks together in the code. - See classes as an opportunity to put data and related methods together.