PD

PD

PPL AND AD

//SLIP_8

Q1.

Create array of strings and read a string from user. Display all the strings from the array that contain the given string.

(accept array and string: 10M, check string logic: 10M


object strdisp

{

def main(args:Array[String])

{

var str:Array[String]=Array("HelloGoodMorning","HelloGoodNight","HelloGoodAfternoon")

var str1=" "

println("Enter string:")

str1=readLine()

var str2=str :+str1

for(j<-str2)

{

println(j)

}

}

}



Q2.

> use inventory_info

switched to db inventory_info

> db.createCollection("item")

{ "ok" : 1 }

> db.item.insert([

  {itemName:"planner",tag:["wash","food","vehicle"],

  status:"A",height:5,width:9,

  instock:15,

  warehouse:[{location:"pune",quantity:36},{location:"mumbai",quantity:67}]

  },

  {itemName:"toycar",tag:["food","vehicle"],

  status:"D",height:5,width:9,

  instock:15,

  warehouse:[{location:"pune",quantity:36},{location:"mumbai",quantity:67}]

  },

  {itemName:"roboticcar",tag:["food","vehicle"],

  status:"A",height:9,width:9,

  instock:5,

  warehouse:[{location:"pune",quantity:26},{location:"mumbai",quantity:17}]

  },

  {itemName:"bag",tag:["food","vehicle","school","travel"],

  status:"A",height:19,width:39,

  instock:75,

  warehouse:[{location:"pune",quantity:26},{location:"mumbai",quantity:17}]

  }

  ])


a. > db.item.find({status:"D","warehouse.quantity":{$gt:30}},{_id:0})

b. > db.item.find({tag:{$size:3}})

c. > db.item.find({$or:[{status:"A"},{"warehouse.quantity":{$lt:30},height:{$gt:10}}]})

d. > db.item.find({itemName:"planner",instock:{$lt:20}})

-----------------------------------------------------------------------------------------------------------

//SLIP_9

Q1.

Create a MAP for storing the following information about 5 students, where each Student is described with Name and Percentage. Display Student information with highest percentage.


object student

{

def main(a:Array[String])

{

var map=Map(1->"mayuri",2->"mayuri",3->"Chinmay",4->"mayuri",5->"mayi");

for((k1,v1) <- map)

{

for((k2,v2)<-map)

{

if(v1==v2 && k1!=k2)

{

println(" Roll No: "+ k1+" FirstName:"+v1);

}

}

}


}


}



Q2.

> use transcation_info

switched to db transcation_info

> db.createCollection("transaction")

{ "ok" : 1 }

> db.transaction.insert([

  {"itemName":"toy",

  "customerName":"john",

  "paymentmode(cash/credit_card/debit_card)":"debit_card",

  "payment":8000

  },

  {"itemName":"car",

  "customerName":"john",

  "paymentmode(cash/credit_card/debit_card)":"credit_card",

  "payment":4000

  },

  {"itemName":"bag",

  "customerName":"mukesh",

  "paymentmode(cash/credit_card/debit_card)":"cash",

  "payment":5000

  },

  {"itemName":"airlineticket",

  "customerName":"rohit",

  "paymentmode(cash/credit_card/debit_card)":"cash",

  "payment":50490

  },

  {"itemName":"mongo",

  "customerName":"abhijeet",

  "paymentmode(cash/credit_card/debit_card)":"credit_card",

  "payment":8000

  },

  {"itemName":"bus",

  "customerName":"john","paymentmode(cash/credit_card/debit_card)":"debit_card",

  "payment":7000

  }

  ])


a. > db.transaction.find({"customerName":"john"})

b. > db.transaction.find({"paymentmode(cash/credit_card/debit_card)":"debit_card"})

c. > db.transaction.aggregate([{$match:{"paymentmode(cash/credit_card/debit_card)":"credit_card"}},

   {$group:{_id:null,"count":{"$sum":"$payment"}}}])

d. > db.transaction.aggregate([{$group:{_id:"$paymentmode(cash/credit_card/debit_card)",

   "count":{"$sum":"$payment"}}}])  

--------------------------------------------------------------------------------------------------------

//SLIP_10

Q1.

Create an abstract class Shape with abstract functions volume() and display(). Extend two classes Cube and Cylinder from it. Create object of Cube and Cylinder. Calculate volume of each and display it.


import scala.annotation.switch

abstract class shape()

{

  def volume()

  def display()

}

class cube(side:Int) extends shape()

{

  var s:Int=side

  var v:Int=0

  def volume()

  {

    v=s*s*s

  }

  def display()

  {

    println("volume is:"+v)

  }

}

class cylinder(radius:Int,height:Int) extends shape()

{

  var r:Int=radius

  var h:Int=height

  var v:Float=0.0f

  var pi=3.14f

  def volume()

  {

     v=pi*(r*r*h)

  }

  def display()

  {

    println("volume of cylinder is:"+v)

  }

}

object slip10

{

  def main(args:Array[String]):Unit=

  {

    println("Enter your choice:1)cube 2)cylinder 3)exit:")

    var ch:Int=scala.io.StdIn.readInt()

    ch match

    {

      case 1 => println("Enter side:")

          var s:Int=scala.io.StdIn.readInt()

          var c=new cube(s)

          c.volume()

          c.display()

      case 2 => println("Enter raadius:")

           var r:Int=scala.io.StdIn.readInt()

           println("Enter height:")

           var h:Int=scala.io.StdIn.readInt()

           var cy=new cylinder(r,h)

            cy.volume()

            cy.display()

      case 3 => System.exit(1)

    }

  }

}



Q2.

> use Online_mobile_shopping

switched to db Online_mobile_shopping

> db.createCollection("shopping")

{ "ok" : 1 }

> db.createCollection("customer")

{ "ok" : 1 }

> db.shopping.insert([

 {brandname:"samsung",rate:6,

  model:[{mname:"s40",ram:"3GB",rom:"32GB",rate:4}]

 },

 {brandname:"samsung",rate:5,

  model:[{mname:"j6",ram:"3GB",rom:"64GB",rate:3}]

 },

 {brandname:"vivo",rate:4,

  model:[{mname:"v20",ram:"3GB",rom:"32GB",rate:5}]

 },

 {brandname:"redmi",rate:5,

  model:[{mname:"note 10",ram:"3GB",rom:"128GB",rate:5}]

 },

 {brandname:"apple",rate:5,

  model:[{mname:"iphone 7plus",ram:"6GB",rom:"128GB",rate:5}]

 }

 ])


> db.customer.insert([

 {cname:"Riya",modelname:"samsung j6",amount:20000},

 {cname:"abhi",modelname:"samsung j6",amount:20000},

 {cname:"gita",modelname:"iphone 7plus",amount:50000},

 {cname:"neha",modelname:"iphone 7plus",amount:50000},

 {cname:"pooja",modelname:"iphone 7plus",amount:50000},

 {cname:"Amey",modelname:"iphone 7plus",amount:50000}

 ])


a. > db.shopping.find({"model.ram":"3GB","model.rom":"32GB"})

b. > db.customer.find({modelname:"samsung j6"},{cname:1,_id:0})

c. > db.shopping.find({},{brandname:1,_id:0})

  > db.shopping.aggregate([{"$sort":{"rate":-1}},{"$limit":1},{$group:{_id:"$brandname"}}])

d. > db.customer.find({"modelname":"iphone 7plus"},{cname:1,_id:0}).sort({"cname":1}).pretty()

---------------------------------------------------------------------------------------------------------

Report Page