OneCompiler

ppl&dbtSlip5

1636

Q1:-

CREATE (s1:Student {name: 'Alice', gender: 'Female', city: 'Pune', percentage: 85}),
(s2:Student {name: 'Bob', gender: 'Male', city: 'Mumbai', percentage: 75}),
(s3:Student {name: 'Cathy', gender: 'Female', city: 'Pune', percentage: 90}),
(s4:Student {name: 'David', gender: 'Male', city: 'Kolhapur', percentage: 65}),
(s5:Student {name: 'Eva', gender: 'Female', city: 'Pune', percentage: 78}),
(s6:Student {name: 'Frank', gender: 'Male', city: 'Mumbai', percentage: 88}),
(s7:Student {name: 'Grace', gender: 'Female', city: 'Pune', percentage: 95}),
(s8:Student {name: 'Henry', gender: 'Male', city: 'Mumbai', percentage: 72}),
(s9:Student {name: 'Ivy', gender: 'Female', city: 'Kolhapur', percentage: 80}),
(s10:Student {name: 'Jack', gender: 'Male', city: 'Pune', percentage: 82})

CREATE (c1:Course {course_name: 'Mathematics', credits: 4}),
(c2:Course {course_name: 'Physics', credits: 3}),
(c3:Course {course_name: 'Chemistry', credits: 3}),
(c4:Course {course_name: 'Biology', credits: 2}),
(c5:Course {course_name: 'Computer Science', credits: 4})

CREATE (s1)-[:REGISTERED_FOR {marks: 85}]->(c1),
(s1)-[:REGISTERED_FOR {marks: 90}]->(c2),
(s2)-[:REGISTERED_FOR {marks: 75}]->(c1),
(s3)-[:REGISTERED_FOR {marks: 95}]->(c3),
(s4)-[:REGISTERED_FOR {marks: 65}]->(c2),
(s5)-[:REGISTERED_FOR {marks: 78}]->(c4),
(s6)-[:REGISTERED_FOR {marks: 88}]->(c1),
(s7)-[:REGISTERED_FOR {marks: 92}]->(c5),
(s8)-[:REGISTERED_FOR {marks: 72}]->(c3),
(s9)-[:REGISTERED_FOR {marks: 80}]->(c4),
(s10)-[:REGISTERED_FOR {marks: 82}]->(c2)

MATCH (s:Student)
WHERE s.percentage > 80
RETURN COUNT(s) AS Students_With_More_Than_80_Percentage

MATCH (s:Student)
WHERE s.gender = 'Female' AND s.city = 'Pune'
RETURN s.name AS Female_Students_In_Pune

Q2:-

import scala.io.StdIn

object StringComparison {
def main(args: Array[String]): Unit = {
// Read two strings from user input
println("Enter the first string:")
val str1 = StdIn.readLine()
println("Enter the second string:")
val str2 = StdIn.readLine()

// a. Compare using == operator
println(s"Comparison using '==' operator: ${str1 == str2}")

// b. Compare using equals() and compareTo() functions
println(s"Comparison using equals(): ${str1.equals(str2)}")
println(s"Comparison using compareTo(): ${str1.compareTo(str2)}")

// c. Find character at position 5 (index 4 in Scala, as indexing starts from 0)
if (str1.length > 4) {
  println(s"Character at position 5 in the first string: ${str1.charAt(4)}")
} else {
  println("The first string does not have a character at position 5.")
}

if (str2.length > 4) {
  println(s"Character at position 5 in the second string: ${str2.charAt(4)}")
} else {
  println("The second string does not have a character at position 5.")
}

}
}