I am new to Java and am trying to make an interactive program which asks you three riddles (the actual program is inspired by The Batman (movie)'s official website www.rataalada.com.
I have initialised the strings, which are meant to be the answers for the riddles. And I have also tried obtaining the input of the user (their answer to the riddle). However, the program does not work and I don't know where I went wrong. Below is my program:
import java.util.concurrent.TimeUnit;
public class rataAlada{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String answer1 = "He lies still";
String answer2 = "Justice";
String answer3 = "A friend";
String guess1;
String guess2;
String guess3;
//initial talk
System.out.println("Hello there.....");
TimeUnit.SECONDS.sleep(2);
System.out.println("I've been waiting for your arrival.....");
TimeUnit.SECONDS.sleep(2);
System.out.println("You might think you are smart, finding this. But if you really are smart, you would be able to solve these riddles.");
TimeUnit.SECONDS.sleep(4);
//riddle number one
System.out.println("Number ONE.");
System.out.println("What does a liar do when he's dead?");
guess1 = in.nextLine();
if (guess1 == answer1){
System.out.println("Correct! But wait, there are still two more.....");
}
else{
System.out.println("You really shouldn't be here. But I pity you. TRY AGAIN.");
guess1 = in.nextLine();
}
//riddle number two
System.out.println("Number TWO.");
System.out.println("It can be cruel, poetic, or blind. But when it is denied, its violence you may find.");
guess2 = in.nextLine();
if (guess2 == answer2){
System.out.println("Good, good, but are you good enough?");
}
else{
System.out.println("We don't have all day. Make another guess.");
guess2 = in.nextLine();
}
//riddle number three
System.out.println("Number THREE.");
System.out.println("The less of me you have, the more I am worth. What am I?");
guess3 = in.nextLine();
if (guess3 == answer3){
System.out.println("You are actually smart. But this isn't the end....");
System.out.println("Visit www.rataalada.com. Your next challenge awaits......");
}
else{
System.out.println("I would kick you off this program but I'm feeling nice. TRY AGAIN.");
guess3 = in.nextLine();
}
}
}