Your mission, should you choose to accept it, involves the recovery of a vital resource stolen from the Central European Republic.
In the wake of an unidentified disaster, rescue dogs were brought in to locate survivors. Special dog food, designed to enhance the dogs' tracking abilities, was pilfered by the notorious international criminal and terrorist, Herr Wolf.
You and The Furr Squad are to retrieve the stolen supplies and bring Herr Wolf to justice.
The fate of the survivors and the entire republic depends on your team.
As always, should any member of your team be caught or killed, the Scretary will disavow any knowledge of your actions.
Good luck, Peanut.
This message will self-destruct in five seconds.
Introduction
In this lab, we'll be helping Agent Peanut, the Bichon Bond, navigate through a labyrinth filled with danger and excitement. As a developer, you'll be providing assistance to Agent Peanut by writing Java code to overcome various obstacles set by Herr Wolf. This lab will improve your skills in Java, problem-solving, and logical thinking.
Environment setup
You will need the latest version of Java installed and an Integrated Development Environment (IDE) such as IntelliJ IDEA or Eclipse.
Lab Exercises
Exercise 1: The Secret Entrance
Agent Peanut has located the secret entrance to Herr Wolf's lair. This entrance is locked by a security code. Your task is to write a Java method to crack the code. The code is a four-digit number with no repeating digits. The only hint given is that the product of these four digits is 24.
publicclassMain {
publicstaticvoidmain(String[] args) {
findCode();
}
publicstaticvoidfindCode() {
for(int i = 1; i < 10; i++) {
for(int j = 1; j < 10; j++) {
for(int k = 1; k < 10; k++) {
for(int l = 1; l < 10; l++) {
if(i != j && i != k && i != l && j != k && j != l && k != l) {
if(i * j * k * l == 24) {
System.out.println("The code is: " + i + j + k + l);
}
}
}
}
}
}
}
}
Exercise 2: Laser Hallway
Agent Peanut has now reached a hallway protected with lasers. You need to write a Java method that will simulate a strategy to help Agent Peanut navigate through the lasers. The hallway can be represented as a 2D array where 0 represents a safe zone, and 1 represents a laser.
Peanut can only move right or down in the grid.
Your task is to find a path from the top left to the bottom right.
// Tip: Use recursion to explore all possible paths
}
}
Exercise 3: Safe Crack
Agent Peanut has located the safe where the stolen dog food is kept. Your mission is to write a Java method that will help Agent Peanut crack the safe. The safe is opened by a sequence of rotations - three turns right to the first number, two turns left to the second number, and one turn right to the final number. All numbers are in the range of 0-99 and the safe has a peculiar property - the sum of the second and third numbers is the first number.
publicclassMain {
publicstaticvoidmain(String[] args) {
crackSafe();
}
publicstaticvoidcrackSafe() {
// Implement your solution here
// You need to find three numbers that satisfy the safe's condition
}
}
Solution using nested for-loops to iterate through all possible combinations of numbers until it finds one that satisfies the conditions:
This code will output the first combination where the sum of the second and third numbers equals the first number. It will stop immediately once it has found a valid combination. If no valid combination is found after checking all possibilities, it will print "No valid combination found".