Grouping Data 3 9 2012 Opening Discussion Minute 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 More Why 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 Midterm Median 77 without EC Distribution 5 As 7 Bs 10 Cs 5 Ds 5 Fs Motivation Consider 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 Types The 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 Instantiation Once we have defined a case class we can make new objects of that type in one of two ways TypeName expr1 expr2 Or new TypeName expr1 expr2 Example var td NBAPlayer Tim Duncan Spurs List 23 13 List 15 17 List 6 8 Usage We 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 Method There 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 Together In 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 Essay What 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 time
View Full Document