官术网_书友最值得收藏!

  • Professional Scala
  • Mads Hartmann Ruslan Shevchenko
  • 277字
  • 2021-07-23 17:24:22

Obtaining the Time Request from Our Chatbot Program

For now, let's return to our task: modifying the chatbot program so that it replies with the current time, as requested by the use of time. Let's learn how to do this:

Steps for C ompletion

  1. Check for time to match the statement:
    case "time" =>
  2. Retrieve the current time using the Java API. Use the now method of java.time.LocalTime:
         java.time.LocalTime.now()
  3. Display the output of the time using string interpolators, as follows:
    println("time is ${java.time.LocalTime.now()}")

The main method will look like this:

def main(args: Array[String]): Unit = {
val name = StdIn.readLine("Hi! What is your name?")
println(s" $name, tell me something interesting, say 'bay' to end the talk")
var timeToBye = false
while (!timeToBye)timeToBye = StdIn.readLine(">") 
match {case "bye" => println("ok, bye")truecase "time" => 
println(s"time is ${java.time.LocalTime.now()}")truecase _ => 
println("interesting...")false}
}

After we prepare and package our artifacts, we need to run them as well.

In this book, we will use the running system from unpackaged sources via sbt (as in the early days of Ruby applications), assuming that sources and sbt tools are accessible from the production environment. Using this, we can use build tool commands for sources such as sbt run. In real life, packaging for production is a bit more complex.

Popular methods for doing this are as follows:

  • Preparing a fat jar (which includes all dependencies). An sbt plugin for this exists, which can be found at the following link: https://github.com/sbt/sbt-assembly.
  • Preparing a native system package (which includes jars, dependencies, custom layouts, and so on). There is also an sbt plugin to create native system packages, which can be found at the following link: https://github.com/sbt/sbt-native-packager.
主站蜘蛛池模板: 普兰县| 安福县| 喀喇| 贵州省| 招远市| 汨罗市| 德州市| 松江区| 长武县| 灌云县| 安西县| 汤阴县| 静宁县| 泉州市| 博野县| 伊春市| 荣昌县| 珲春市| 遵义市| 柞水县| 扎鲁特旗| 涪陵区| 平安县| 青海省| 通辽市| 全南县| 资溪县| 武汉市| 青铜峡市| 永泰县| 博野县| 容城县| 白银市| 黔东| 侯马市| 屯留县| 湘西| 罗城| 河源市| 眉山市| 延津县|