I don't want to add all of the code as it is a game i am making currently. Anyways, I declared class_Selection, and Characterclass. The user enters a string for class_Selection. It displays the result and then proceeds into an if statement in which it uses that same input to decide on what to do afterwards. I am very new to java, and coding for that matter and this is my first project. The problem is probably simple. As you can see I placed it in all caps because I heard that if its in all caps no matter how the user enters it, it will accept that key, such as: MeLeE, That may not be true. The result produces as it goes through the rest of the program correctly even displays the results for class_Selection but when it gets to the if- statements it displays null.
Edit The problem is somehow character class is equal to null so when I System.out.println(Characterclass); I am receiving null.
I fixed the ==, thank you for that, but I need to fix CharacterClass somehow ending up to be null.
EDIT The problem was, in the IF-statement I had the answer in all caps, I know there is probably a way to do that, but I wasn't doing it right. If I enter the right key such as if it is MELEE, I enter MELEE it will display the results. Also I think when I did the system.out.println(Characterclass); , I didn't have a method that ran it so I am going to fix that. I got it to display the bonuses.
Thank you for the == problem, I am a step farther on my goal.
// Class Selection
System.out.println("Which one did you excel in ( Class )? Melee, Magic, or Archery?"); // Class selection
String class_Selection; // Hold the class name (make method with this to declare bonuses and things that have to do with the class he chose: such as If ( class_Selection == melee)
class_Selection = classSelection.next(); // User enters name of class they want
System.out.println("You entered: " + class_Selection + (" Is this the class you want?, y or n?"));
String yOrN;
yOrN = defaultScanner.next();
if (yOrN == "n") { // redo if selection is no
System.out.println("Then which class would you like? Melee, Magic, Archery?");
class_Selection = classSelection.next();
System.out.println("You entered: " + class_Selection + (" Is this the class you want?, y or n?"));
yOrN = defaultScanner.next();
}else{ // Does nothing if y because the selection is correct
}
// Continue after class selection
System.out.println("Your class is: " + class_Selection); // Final display
System.out.println("\n");
// This is where your selection takes effect and displays your bonuses
if (class_Selection == "MELEE") {
Characterclass = "melee";
System.out.println("Melee = +5 Blade, +5 Blunt, +5 Hand-To-Hand, +5 Heavy Armor,");
}
if (class_Selection == "ARCHERY") {
Characterclass = "Archery";
System.out.println("+10 Archery, + 10 Light Armor");
}
if (class_Selection == "MAGIC") {
Characterclass = "Magic";
System.out.println(" +10 Arcane, +5 Light Armor");
}
System.out.println(Characterclass);
}
}