Help with enums in Java

Posted by devoured elysium on Stack Overflow See other posts from Stack Overflow or by devoured elysium
Published on 2010-04-15T17:41:25Z Indexed on 2010/04/15 17:43 UTC
Read the original article Hit count: 100

Filed under:
|

Is it possible to have an enum change its value (from inside itself)? Maybe it's easier to understand what I mean with code: enum Rate { VeryBad(1), Bad(2), Average(3), Good(4), Excellent(5);

    private int rate;

    private Rate(int rate) {
        this.rate = rate;
    }

        public void increateRating() {
            //is it possible to make the enum variable increase?
            //this is, if right now this enum has as value Average, after calling this
            //method to have it change to Good?
       }
}

This is want I wanna achieve:

Rate rate = Rate.Average;
System.out.println(rate); //prints Average;
rate.increaseRating();
System.out.println(rate); //prints Good

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about enum