-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.1.scala
32 lines (25 loc) · 866 Bytes
/
5.1.scala
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
import scala.io.StdIn.readLine
object InventoryManagement{
def getProductList(): List[String] = {
def loop(acc: List[String]): List[String] ={
val input = readLine("Enter produxt name(or type'done' to finish):")
if(input.toLowercase == "done") acc
else loop(acc:+ input)
}
loop(Nil)
}
def printProductList(products: List[String]): Unit ={
products.zipWithIndex.foreach{case(product,index) =>
println()(s"${index+1}.$product")
}
}
def getTotalProducts(products:List[String]) : Int ={
products.length
}
def main(args: Array[String]):Unit ={
val products = getProductList()
println("\nProduct List:")
printProductList(products)
println("\nTotal number of products : ${getTotalProducts(products)}")
}
}