// EthanHunt.java
public class EthanHunt {
private boolean hasUSBKey;
public EthanHunt() {
hasUSBKey = false;
}
public void retrieveUSBKey() {
hasUSBKey = true;
}
public boolean hasUSBKey() {
return hasUSBKey;
}
}
// EnemyEmbassy.java
public class EnemyEmbassy {
private final USBKey usbKey;
public EnemyEmbassy(SecretDocuments secretDocuments) {
usbKey = new USBKey(secretDocuments);
}
public USBKey getUSBKey() {
return usbKey;
}
}
// SecretDocuments.java
public class SecretDocuments {
private boolean worldWar3Prevented;
public SecretDocuments() {
worldWar3Prevented = false;
}
public void preventWorldWar3() {
worldWar3Prevented = true;
}
public boolean isWorldWar3Prevented() {
return worldWar3Prevented;
}
}
// USBKey.java
public class USBKey {
private final SecretDocuments secretDocuments;
public USBKey(SecretDocuments secretDocuments) {
this.secretDocuments = secretDocuments;
}
public SecretDocuments getSecretDocuments() {
return secretDocuments;
}
}
// MissionImpossibleGame.java
import java.util.Scanner;
public class MissionImpossibleGame {
public static void main(String[] args) {
EthanHunt ethanHunt = new EthanHunt();
SecretDocuments secretDocuments = new SecretDocuments();
EnemyEmbassy enemyEmbassy = new EnemyEmbassy(secretDocuments);
System.out.println("Welcome to the Mission Impossible game!");
System.out.println("Your mission, should you choose to accept it, is to help Ethan Hunt retrieve the USB key from the Enemy Embassy containing the Secret Documents that will prevent World War 3.");
System.out.println("Type 'start' to begin.");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
if (input.equalsIgnoreCase("start")) {
System.out.println("You have entered the Enemy Embassy. Type 'retrieve' to retrieve the USB key.");
input = scanner.nextLine();
if (input.equalsIgnoreCase("retrieve")) {
ethanHunt.retrieveUSBKey();
System.out.println("Ethan has successfully retrieved the USB key!");
if (ethanHunt.hasUSBKey()) {
USBKey usbKey = enemyEmbassy.getUSBKey();
SecretDocuments retrievedDocuments = usbKey.getSecretDocuments();
retrievedDocuments.preventWorldWar3();
if (retrievedDocuments.isWorldWar3Prevented()) {
System.out.println("Congratulations! You have successfully prevented World War 3!");
}
}
} else {
System.out.println("Invalid input. Mission failed.");
}
} else {
System.out.println("Invalid input. Mission failed.");
}
scanner.close();
}
}