Advertisement
Guest User

f****** SCALA!!!

a guest
Mar 23rd, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.08 KB | None | 0 0
  1. object CalculateShapes extends App {
  2.  
  3.   import scala.io.StdIn.readLine
  4.  
  5.   val height = """(\d*,*\d*)\s*(mm|cm|dm|m)""".r
  6.   val inputHeight = readLine("Please insert the height of your shape:\n")
  7.   val height(value,metric) = inputHeight
  8.  
  9.   val width = """(\d*,*\d*)\s*(mm|cm|dm|m)""".r
  10.   val inputWidth = readLine("Please insert the width of your shape:\n")
  11.   val width(wert,maße) = inputWidth
  12.  
  13.   val shape = """(rectangle|triangle|circle)""".r
  14.   val inputShape = readLine("Enter the type of your shape (rectangle, triangle or circle):\n")
  15.   val shape(form) = inputShape
  16.  
  17.   var temp:Double = value.toDouble
  18.  
  19.   def defineHeight(value:String,metric:String) : Double = {
  20.     metric match {
  21.      case "mm" => return temp/10
  22.      case "cm" => return temp
  23.      case "dm" => return temp*10
  24.      case "m" => return temp*100
  25.    }
  26.   }
  27.  
  28.   println(defineHeight(value,metric))
  29.  
  30.   val area = (value.replace(",",".").toDouble * wert.replace(",",".").toDouble)
  31.   println(f"The area of your $form with height=${temp}cm and width=${wert}cm is: $area%.2f${metric}2")
  32.    
  33.  
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement