Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Grouping Data3-9-2012Opening DiscussionMinute essay comments:What does the map function do?If robots took over would it be like Terminator 4? Would I be up to leading the resistance?Would it be more efficient to make your own file writing code than using PrintWriter?Use of args: file names, flags, etc.Limits on files determined by OS.Does moving IcP #5 push back our schedule?Always close at end of file?Is there a backspace on typewriters?MoreWhy do Java libraries work? Other languages?What will automated cars do to car racing?Effective use of programming time.Educational programming mediums: Scratch and Alice.Collections normally in memory. Source is loading from disk.Virtual boyfriends/girlfriends.Duplicating Watson is relatively cheap. Service.IcP solutions.MidtermMedian = 77 (without EC)Distribution5 As7 Bs10 Cs5 Ds5 FsMotivationConsider things like a Point, a Student, a CD, or a Room in a text game.We can use a tuple to group pieces of data together, but this doesn't carry much meaning and leads to ugly, bug-prone code.We want a better way to express these groupings that carries more information.User Defined TypesThe general way we do this is to define our own types.For now we will just use these types to collect data together in a case class.This allows us to give meaning to the data with meaningful names.case class TypeName(field1:Type1,field2:Type2,...)Example:case class NBAPlayer(name:String, team:String, mins:List[Int], points:List[Int], rebounds:List[Int])InstantiationOnce we have defined a case class we can make new objects of that type in one of two ways.TypeName(expr1,expr2,...)Ornew TypeName(expr1,expr2,...)Example:var td=NBAPlayer(“Tim Duncan”, ”Spurs”, List(23,13), List(15,17), List(6,8))UsageWe can pull out values using dot notation and the name of the field.Example:println(td.name+” averages “+td.points.sum/td.points.length+” ppg”)The fields are vals so you can't change what they reference. You can only change their values if they are mutable.Copy MethodThere is a copy method on case classes that does what the name implies.It can take named arguments to change certain fields in the copy.Example:td=td.copy(mins=17::td.mins, points=15::td.points, rebounds=4::td.rebounds)Putting it TogetherIn the book I am building an example application of a grade book. I'd like to do something different in class so you see variety.Do you have any suggestions or do you want me to come up with something? (CPI handling, player stats, ...)Minute EssayWhat topics would you most like to have video lectures for?Imagine you live in a world of abundance where you can have anything that has been created without needing money, but people need to work to create new ideas/designs/technology/science/knowledge. What would you do with your
View Full Document