0

so I have a base class where I define an enum variable with this block of code.

    enum Faction {
            AMITY, ABNIGATION, DAUNTLESS, EURIDITE, CANDOR
        };

And I'm trying to test to see if everything in my subclass works by using a driver. My constructor in my subclass looks like this.

public Dauntless(String f, String l, int a,  int ag, int end, Faction d) {
        super(f, l, a, d);
        if (ag >= 0 && ag <= 10) {
            this.agility = ag;
        } else {
            this.agility = 0;
        }
        if (end >= 0 && end <= 10) {
            this.endurance = end;
        } else {
            this.endurance = 0;
        }
    }

And my driver looks like this

public class Test {
    public static void main(String[] args) {
        Faction this = Faction.DAUNTLESS;
        Dauntless joe = new Dauntless("Joseph", "Hooper", 20, 5, 3, this);
        Dauntless vik = new Dauntless("Victoria", "Ward", 19, 6, 2, this);
        Dauntless winner;
        winner = joe.battle(vik);
        System.out.println(winner);


}

It keeps saying that Faction this = Faction.DAUNTLESS;is not a statement. Can somebody help me out here?

2
  • 4
    this is a keyword in Java. Commented Mar 4, 2015 at 0:31
  • 1
    subclass of what??? Commented Mar 4, 2015 at 0:32

1 Answer 1

1

As mentioned in the comments, this is a keyword in Java, used for things like:

this.faction;

You can't use keywords as variable names. Just change the variable name:

Faction this_faction = Faction.DAUNTLESS;

Then, of course, you need to change references to the variable:

Dauntless joe = new Dauntless("Joseph", "Hooper", 20, 5, 3, this_faction);
Dauntless vik = new Dauntless("Victoria", "Ward", 19, 6, 2, this_faction);
Sign up to request clarification or add additional context in comments.

1 Comment

I should've figured that out. I made the changes and now i'm getting. Cannot find symbol for Faction. Did i define my enums wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.