OneCompiler

ppl&dbtSlip12

1718

Q1:-

CREATE (p1:Publisher {name: 'Publisher A', location: 'Mumbai', established_year: 1990}),
(p2:Publisher {name: 'Publisher B', location: 'Delhi', established_year: 1985}),
(p3:Publisher {name: 'Publisher C', location: 'Mumbai', established_year: 2000}),
(p4:Publisher {name: 'Publisher D', location: 'Chennai', established_year: 1995}),
(p5:Publisher {name: 'Publisher E', location: 'Mumbai', established_year: 2010}),
(p6:Publisher {name: 'Publisher F', location: 'Kolkata', established_year: 1998}),
(p7:Publisher {name: 'Publisher G', location: 'Mumbai', established_year: 2005}),
(p8:Publisher {name: 'Publisher H', location: 'Delhi', established_year: 2018}),
(p9:Publisher {name: 'Publisher I', location: 'Pune', established_year: 2016}),
(p10:Publisher {name: 'Publisher J', location: 'Mumbai', established_year: 2020});

CREATE (b1:Book {title: 'Book A', author: 'Author A', cost: 1200}),
(b2:Book {title: 'Book B', author: 'Author B', cost: 800}),
(b3:Book {title: 'Book C', author: 'Author C', cost: 1500}),
(b4:Book {title: 'Book D', author: 'Author D', cost: 950}),
(b5:Book {title: 'Book E', author: 'Author E', cost: 600}),
(b6:Book {title: 'Book F', author: 'Author F', cost: 2000}),
(b7:Book {title: 'Book G', author: 'Author G', cost: 750}),
(b8:Book {title: 'Book H', author: 'Author H', cost: 1100}),
(b9:Book {title: 'Book I', author: 'Author I', cost: 990}),
(b10:Book {title: 'Book J', author: 'Author J', cost: 1350});

CREATE (p1)-[:PUBLISHES]->(b1),
(p1)-[:PUBLISHES]->(b2),
(p3)-[:PUBLISHES]->(b3),
(p4)-[:PUBLISHES]->(b4),
(p5)-[:PUBLISHES]->(b5),
(p6)-[:PUBLISHES]->(b6),
(p7)-[:PUBLISHES]->(b7),
(p8)-[:PUBLISHES]->(b8),
(p9)-[:PUBLISHES]->(b9),
(p10)-[:PUBLISHES]->(b10);

MATCH (p:Publisher)
WHERE p.location = 'Mumbai'
RETURN p.name AS Publisher_Name, p.established_year AS Established_Year;

MATCH (b:Book)
WHERE b.cost > 1000
RETURN b.title AS Book_Title, b.author AS Author, b.cost AS Cost;

Q2:-

object SetOperations {
def main(args: Array[String]): Unit = {
// Define two sets of integers
val set1 = Set(1, 2, 3, 4, 5)
val set2 = Set(4, 5, 6, 7, 8)

// Merge the two sets
val mergedSet = set1 ++ set2

// Print the merged set
println(s"Merged Set: $mergedSet")

// Calculate the product of all elements in the merged set
val product = mergedSet.product

// Calculate the average of all elements in the merged set
val average = if (mergedSet.nonEmpty) mergedSet.sum.toDouble / mergedSet.size else 0.0

// Print the product and average
println(s"Product of elements: $product")
println(f"Average of elements: $average%.2f") // Print average rounded to 2 decimal places

}
}