I'm new to learning Java. I started about a week ago, and have spent around 10 hours a day learning, and I'm not sure if I'm behind where I "should be" (another concern I'm dealing with) I'm aware that my code is probably not the most efficient, but I have to start somewhere, and I've typed most of this out of memory from the cosmos of information I've read in the last week. Right now, I'm just trying to make games or apps to help solidify concepts of programming. To put what I've learned to use and make this information relevant.
my question is, essential, why are my "if" statements going directly to the "else"?
public class ClassSelect {
public static String className;
public static void pickPlayer() {
Scanner scan = new Scanner(System.in);
System.out.println("Pick your class." + "\n" + "[F]ighter" + "\n"
+ "[W]izard");
String scanClass = scan.nextLine();
if ((scanClass == "f") || (scanClass == "F")) {
System.out.println("You picked the Fighter");
String classNameF = "Fighter";
className = classNameF;
try {
File file = new File("saveData.txt");
BufferedWriter output = new BufferedWriter(new FileWriter(file));
output.write(className);
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
else if ((scanClass == "w") || (scanClass == "W")) {
System.out.println("You picked the Wizard");
String classNameW = "Wizard";
className = classNameW;
try {
File file = new File("saveData.txt");
BufferedWriter output = new BufferedWriter(new FileWriter(file));
output.write(className);
output.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("You didn't choose either.");
}
}