dgadiraju
5/8/2017 - 1:51 PM

RetailCase.scala

package retail

/**
  * Created by itversity on 08/05/17.
  */
case class Department(
                       departmentId: Int,
                       departmentName: String
                     )

case class Category(
                     categoryId: Int,
                     categoryDepartmentId: Int,
                     categoryName: String
                   )


case class Product(
                    productId: Int,
                    productCategoryId: Int,
                    productName: String,
                    productDescription: String,
                    productPrice: Float,
                    productImage: String
                  )

case class Customer(
                     customerId: Int,
                     customerFname: String,
                     customerLname: String,
                     customerEmail: String,
                     customerPassword: String,
                     customerStreet: String,
                     customerCity: String,
                     customerState: String,
                     customerZipcode: String
                   )

case class Order(
                  orderId: Int,
                  orderDate: String,
                  orderCustomerId: Int,
                  orderStatus: String
                )

case class OrderItem(
                      orderItemId: Int,
                      orderItemOrderId: Int,
                      orderItemProductId: Int,
                      orderItemQuantity: Int,
                      orderItemSubtotal: Float,
                      orderItemProductPrice: Float
                    ) {
  require(
    orderItemSubtotal == orderItemQuantity * orderItemProductPrice, "Invalid orderItemSubtotal " + orderItemSubtotal
  )

  //Additional constructor
  def this(
            orderItemId: Int,
            orderItemOrderId: Int,
            orderItemProductId: Int,
            orderItemQuantity: Int,
            orderItemProductPrice: Float
          ) = {
    //Invoking default constructor
    this(orderItemId,
      orderItemOrderId,
      orderItemProductId,
      orderItemQuantity,
      orderItemQuantity * orderItemProductPrice,
      orderItemProductPrice)
  }
}

object retail {
  def main(args: Array[String]) = {
    val oi = new OrderItem(1, 1, 1, 2, 100, 50)
    println(oi)
    val ordItem = new OrderItem(2, 1, 3, 3, 50)
    println(ordItem)
  }
}