開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Scala (プログラミング言語)
Learning Scala: Practical Functional Programming for the JVM (Jason Swartz (著)、O'Reilly Media)のPart 2. (Object-Oriented Scala)、Chapter 8.(Classes)、Exercises 1-b.(No. 3847)を解いてみる。
その他参考書籍
Exercises 1-b.(No. 3847)
コード(Emacs)
import java.util.Date
class Console(val make:String, val model:String, val debut:Date,
val wifi_type:Option[String], val formats:List[String], val resolution:Int) {
override def toString = s"make: $make, model: $model, debut: $debut, " +
s"wifi type: $wifi_type, formats: $formats, resolution: $resolution"
}
val c1 = new Console("make1", "model1", new Date(), Option("b/g"),
List("format0", "format1"), 10)
val c2 = new Console("make2", "model2", new Date(), Option("b/g"),
List("format0", "format1"), 10)
val c3 = new Console("make3", "model3", new Date(), Option("b/g"),
List("format0", "format1"), 10)
val c4 = new Console("make4", "model4", new Date(), Option("b/g"),
List("format0", "format1"), 10)
for (c <- Seq(c1, c2, c3, c4)) {
println(c)
}
入出力結果(Terminal, REPL(Read, Eval, Print, Loop))
$ scala-2.11 sample1_b.scala make: make1, model: model1, debut: Thu Jan 14 14:20:17 JST 2016, wifi type: Some(b/g), formats: List(format0, format1), resolution: 10 make: make2, model: model2, debut: Thu Jan 14 14:20:17 JST 2016, wifi type: Some(b/g), formats: List(format0, format1), resolution: 10 make: make3, model: model3, debut: Thu Jan 14 14:20:17 JST 2016, wifi type: Some(b/g), formats: List(format0, format1), resolution: 10 make: make4, model: model4, debut: Thu Jan 14 14:20:17 JST 2016, wifi type: Some(b/g), formats: List(format0, format1), resolution: 10 $
0 コメント:
コメントを投稿