lunlumo #6958(2008/08/03 17:41 GMT) [ Scala ] Rating0/0=0.00
こんな感じでしょうか。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
import java.io.BufferedInputStream import java.io.FileInputStream import java.io.FileNotFoundException import java.util.Properties class LoadPrice(val propertyFile:String) { private var properties:Properties[String,String] = null private var name:String = null private var cost:int = 0 def load:LoadPrice = { val properties = new Properties[String,String] val stream = new BufferedInputStream(new FileInputStream(propertyFile)) properties.load(stream) stream.close this.properties = properties this.name = properties.getProperty("ITEM_NAME") this.cost = Integer.parseInt(properties.getProperty("ITEM_COST")) this } def getName:String = { name } def getCost:int = { cost } } object ShowPrice { def showPrice(loaded:LoadPrice):Unit = { Console.printf("「%s」は%d円(税込み)\n",loaded.getName,loaded.getCost) } def main(args:Array[String]):Unit = { try { showPrice(new LoadPrice(args(0)).load) } catch { case e:FileNotFoundException => Console.println("property file not found.") case e:Exception => e.printStackTrace } } }
Rating0/0=0.00-0+
[ reply ]
lunlumo #6958() [ Scala ] Rating0/0=0.00
こんな感じでしょうか。
import java.io.BufferedInputStream import java.io.FileInputStream import java.io.FileNotFoundException import java.util.Properties class LoadPrice(val propertyFile:String) { private var properties:Properties[String,String] = null private var name:String = null private var cost:int = 0 def load:LoadPrice = { val properties = new Properties[String,String] val stream = new BufferedInputStream(new FileInputStream(propertyFile)) properties.load(stream) stream.close this.properties = properties this.name = properties.getProperty("ITEM_NAME") this.cost = Integer.parseInt(properties.getProperty("ITEM_COST")) this } def getName:String = { name } def getCost:int = { cost } } object ShowPrice { def showPrice(loaded:LoadPrice):Unit = { Console.printf("「%s」は%d円(税込み)\n",loaded.getName,loaded.getCost) } def main(args:Array[String]):Unit = { try { showPrice(new LoadPrice(args(0)).load) } catch { case e:FileNotFoundException => Console.println("property file not found.") case e:Exception => e.printStackTrace } } }Rating0/0=0.00-0+
[ reply ]