Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object CalculateShapes extends App {
- import scala.io.StdIn.readLine
- val height = """(\d*,*\d*)\s*(mm|cm|dm|m)""".r
- val inputHeight = readLine("Please insert the height of your shape:\n")
- val height(value,metric) = inputHeight
- val width = """(\d*,*\d*)\s*(mm|cm|dm|m)""".r
- val inputWidth = readLine("Please insert the width of your shape:\n")
- val width(wert,maße) = inputWidth
- val shape = """(rectangle|triangle|circle)""".r
- val inputShape = readLine("Enter the type of your shape (rectangle, triangle or circle):\n")
- val shape(form) = inputShape
- var temp:Double = value.toDouble
- def defineHeight(value:String,metric:String) : Double = {
- metric match {
- case "mm" => return temp/10
- case "cm" => return temp
- case "dm" => return temp*10
- case "m" => return temp*100
- }
- }
- println(defineHeight(value,metric))
- val area = (value.replace(",",".").toDouble * wert.replace(",",".").toDouble)
- println(f"The area of your $form with height=${temp}cm and width=${wert}cm is: $area%.2f${metric}2")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement