mercredi 7 septembre 2016

If else statement fails to run conditional code

So I'm a new person when it comes to java. While I'm grasping some of the concepts pretty okay I'm not understanding why this if else statement will not run it's conditional code. I have been looking at others and I changed the notation almost three times and it has yet to work. It's also a long code so I'll cut out the irrelevant parts before it.

        String characterType = keyboard.nextLine();
        System.out.println("");
        final String CHARACTERTYPE = characterType;
        printWriter.println(CHARACTERTYPE);
        if(Objects.equals("Rouge", CHARACTERTYPE) || Objects.equals("rouge", CHARACTERTYPE) || Objects.equals("Thief", CHARACTERTYPE) || Objects.equals("thief", CHARACTERTYPE))
        {   
            System.out.println("Oh so you're a " + characterType + " eh? Must like sneaking around and all that?");
        }
        else if(Objects.equals("Knight", CHARACTERTYPE) || Objects.equals("knight", CHARACTERTYPE) || Objects.equals("Paladin", CHARACTERTYPE) || Objects.equals("paladin", CHARACTERTYPE))
        {
            System.out.println("Oh so you're a " + characterType + " eh? You like to fight your battles and tank hits right?");
        }
        printWriter.close();

So what happens is that I input the String value for characterType and I am testing for characterType of Rogue. But it displays nothing and the program ends (This is at the end of the code.) I've tried just doing CHARACTERTYPE.equals("Rouge") but it does the same. I've tried using characterType.equals("Rouge") it also displays nothing. What is it I'm doing wrong? And to answer any potential problems, everything works. It accepts input and it does write it to the file I have it going to. So I know that printWriter.close(); is being executed or else the file won't save. So it's purely this block.

I'm sorry for being so wordy, just trying to make sure I clearly explain myself.

Aucun commentaire:

Enregistrer un commentaire