ppl&dbtSlip7
Q1:-
CREATE
(a:Person {name: 'Amita', gender: 'Female', age: 30}),
(b:Person {name: 'Ravi', gender: 'Male', age: 32}),
(c:Person {name: 'Sneha', gender: 'Female', age: 28}),
(d:Person {name: 'Raj', gender: 'Male', age: 35}),
(e:Person {name: 'Kiran', gender: 'Female', age: 40}),
(f:Person {name: 'Vikram', gender: 'Male', age: 29}),
(g:Person {name: 'Pooja', gender: 'Female', age: 25}),
(h:Person {name: 'Amit', gender: 'Male', age: 33}),
(i:Person {name: 'Nisha', gender: 'Female', age: 38}),
(j:Person {name: 'Suresh', gender: 'Male', age: 31}),
(a)-[:FRIEND]->(b),
(a)-[:FRIEND]->(c),
(b)-[:FRIEND]->(d),
(c)-[:FRIEND]->(e),
(d)-[:FRIEND]->(f),
(e)-[:FRIEND]->(g),
(f)-[:FRIEND]->(h),
(g)-[:FRIEND]->(i),
(h)-[:FRIEND]->(j);
CREATE
(a)-[:SIBLING]->(c),
(b)-[:SIBLING]->(d),
(e)-[:SIBLING]->(i);
CREATE
(e)-[:PARENT]->(a),
(e)-[:PARENT]->(c),
(d)-[:PARENT]->(b),
(d)-[:PARENT]->(f);
MATCH (m:Person)-[:PARENT]->(child:Person)
WHERE m.gender = 'Female'
RETURN m.name AS Mother_Name;
MATCH (a:Person {name: 'Amita'})-[:FRIEND]->(friend:Person)
RETURN friend.name AS Friend_Name;
Q2:-
class CurrentAccount(val accNo: String, val name: String, private var balance: Double, val minBalance: Double) {
// Method to deposit money
def deposit(amount: Double): Unit = {
if (amount > 0) {
balance += amount
println(s"Deposited: balance")
} else {
println("Deposit amount must be positive.")
}
}
// Method to withdraw money
def withdraw(amount: Double): Unit = {
if (amount <= 0) {
println("Withdrawal amount must be positive.")
} else if (balance - amount < minBalance) {
println(s"Cannot withdraw minBalance must be maintained.")
} else {
balance -= amount
println(s"Withdrew: balance")
}
}
// Method to view the current balance
def viewBalance(): Unit = {
println(s"Current balance: $balance")
}
}
object CurrentAccountApp {
def main(args: Array[String]): Unit = {
// Creating a CurrentAccount object
val account = new CurrentAccount("CA123456", "John Doe", 5000.0, 1000.0)
// Performing operations
account.viewBalance() // View initial balance
account.deposit(1500.0) // Deposit money
account.withdraw(2000.0) // Withdraw money
account.viewBalance() // View updated balance
account.withdraw(4000.0) // Attempt to withdraw more than allowed
account.viewBalance() // Final balance check
}
}