Developing Scala applications using IDE

As part of this session, we will be talking about

  • Run a Scala application via IntelliJ IDEA
  • Develop logic using Map Reduce API

Run a Scala application via IntelliJ IDEA

  1. Create or import a Scala project as you would normally create or import any other project in IntelliJ IDEA.
  2. Open your application in the editor.
  3. Press Shift+F10 to execute the application. Alternatively, in the left gutter of the editor, click the icon and select Run ‘name’.

GetRevenueForEachOrder

import scala.io.Source
object GetRevenueForEachOrder {
  def main(args: Array[String]): unit = {
    val inputpath = args(0)
    val orderId = arg(1).toInt
    val orderItems: Seq[String] = Source.
      fromFile(inputPath).
      getLines.
      toList
    val RevenueForEachOrderId = orderItems.
      filter(oi => oi.split(",")(1).toInt == orderId).
      map(oi => oi.split(",")(4).toFloat).
      reduce(_ + _)
    println(orderRevenue)
  }
}