I am trying to do a program that uses call methods. However, when this is compiled the program tries to read dataIn as a symbol and gives me the error: Cannot find variable
I cannot seem to find the problem to why this is happening. Any help?
import java.util.Random;
import java.io.*;
public class Adventure1 {
public static void main(String[] args) throws IOException {
String strInput = "Y";
while (strInput == "Y") {
int caveNo;
doIntro();
caveNo = getChoice();
doTest(caveNo);
System.out.println("Do you want to play again? (Y or N)");
strInput = dataIn.readLine();
}
}
//Start game
public static void doIntro() {
System.out.println("You are in a land full of dragons. In front of you,");
System.out.println("you see two caves. In one cave, the dragon is friendly");
System.out.println("and will share his treasure with you. The other dragon");
System.out.println("is greedy and hungry, and will eat you on sight.");
System.out.println("");
}
//Choosing a cave
public static int getChoice() {
String strCave;
int intCave;
while (strCave != "1" && strCave != "2") {
System.out.println("Choose a cave (1 or 2)");
strCave = dataIn.readLine();
intCave = Integer.parseInt(strCave);
}
return intCave;
}
//Determining which cave you picked
public static int doTest(int intCave) {
Random ran = new Random();
int friendlyCave = ran.nextInt(1) + 1;
}
}
This is what happens when I compile:
E:\CMIN216\Adventure1.java:15: error: cannot find symbol
strInput = dataIn.readLine();
^
symbol: variable dataIn
location: class Adventure1
E:\CMIN216\Adventure1.java:37: error: cannot find symbol
strCave = dataIn.readLine();
^
symbol: variable dataIn
location: class Adventure1
2 errors
Tool completed with exit code 1
Code is incomplete, by the way. I was so busy on trying to fix this that I did not finish it.