Guest User

Untitled

a guest
May 3rd, 2015
288
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. object MyCameraCollection02 {
  2.  
  3.   case class Camera(brand: String, model: String, sensorType: String, yearBought: Int) {
  4.     override def toString: String =
  5.       s"$brand $model \t\t $sensorType \t($yearBought)"
  6.   }
  7.  
  8.   def main(args: Array[String]) {
  9.     val canon5dmarkIII = new Camera("Canon", "5D MkIII", "FF", 2013)
  10.     val canon5dmarkII = new Camera("Canon", "5D MkII", "FF", 2009)
  11.     val canon6d = new Camera("Canon", "6D", "FF", 2014)
  12.     val canon550d = new Camera("Canon", "550D", "APS-C", 2010)
  13.     val canon40d = new Camera("Canon", "40D", "APS-C", 2008)
  14.     val canonIXUS330 = new Camera("Canon", "IXUS 330", "1/2.7", 2001)
  15.     val canonIXUSZ90 = new Camera("Canon", "IXUS Z90", "APS-C", 1999)
  16.     val panasonicGM1 = new Camera("Panasonic", "GM1", "M43", 2014)
  17.     val panasonicFZ20 = new Camera("Panasonic", "FZ20", "1/2.5", 2005)
  18.     val sonyrx100 = new Camera("Sony", "DSC-RX100", "1\"", 2013)
  19.     val sonynex5 = new Camera("Sony", "NEX-5", "APS-C", 2011)
  20.     val sonyr1 = new Camera("Sony", "DSC-R1", "APS-C", 2005)
  21.  
  22.     val myCameras = List(canon5dmarkIII, canon5dmarkII, canon6d, canon550d, canon40d, canonIXUS330, canonIXUSZ90, panasonicGM1, panasonicFZ20, sonyrx100, sonynex5, sonyr1)
  23.     val canonCameras = myCameras filter (_.brand == "Canon") // Every Canon camera I ever owned
  24.     val sonyCameras = myCameras filter (_.brand == "Sony") // Every Sony camera I ever owned
  25.     val pansonicCameras = myCameras filter (_.brand == "Panasonic") // Every Panasonic camera I ever owned
  26.  
  27.  
  28.     // apscCamera's only
  29.     val apscCameras = myCameras filter (_.sensorType == "APS-C")
  30.     println("==APS-C camera's owned==")
  31.     apscCameras foreach println
  32.     println()
  33.  
  34.  
  35.     // Canon camera's which are not full frame. You can filter, filtered lists.
  36.     val canonNonFF = myCameras filter (_.brand == "Canon") filter (_.sensorType != "FF")
  37.     println("==Non-FF camera's owned==")
  38.     canonNonFF foreach println
  39.     println()
  40.  
  41.     // Filter by boolean expressions on class properties
  42.     val apsBefore2012 = apscCameras filter (_.yearBought < 2012)
  43.     println("==APS-C camera's bought before 2012 owned==")
  44.     apsBefore2012 foreach println
  45.     println()
  46.  
  47.     // Filter by combining boolean expressions.
  48.     val ffcamerasBefore2012 = myCameras filter (cam => cam.yearBought < 2012 && cam.sensorType == "FF")
  49.     println("==Every FF Camera I ever owned before 2012==")
  50.     ffcamerasBefore2012 foreach println
  51.     println()
  52.   }
  53. }
RAW Paste Data