Ah, I've just read through the Comparable interface's API and it somewhat makes sense now. So what I really want is my own original method compareTypes because compareTo is designed so that it sets the elements in a specific order for sorting maps and the like. I get it. I feel better about writing my own method now. Thanks.

OK, so I have an enum with about 15 types in it, representing elements such as water, grass, fire and such. I made the enum implement Comparable<E> and rewrote the compareTo method. BUT apparently compareTo is final and I am not allowed to override it. The final version of compareTo compares them based on their ordering, but there is no logical way to order the types so that the relationships are modeled correctly. For example, the ordering

WATER FIRE GRASS GROUND...

water is strong to fire, fire is strong to grass and grass is strong to ground. BUT water is also strong to ground, and grass is strong to water.....

the obvious option is to write a different method called compareTypes( Type ) or something to that effect but it feels wrong. It feels broken... I really wanted a compareTo method...

So how exactly would I go about changing the global reference rather than creating a new local reference?

I see where the break is...

It seemed to me that when I say

changeInteger( wrapperI );

that I'm passing a pointer to an Integer object into the method and inside the method, the parameter i is pointing to the same thing as global variable wrapperI. So when I changed i inside of the method it should also change wrapperI.

BUT, when I said i = new Integer( 100 ), i no longer pointed to what wrapperI pointed to. And I'm assuming ( by looking at the API ) that Integer is immutable, therefore there is no way to change its value without creating a new instance of Integer and assigning to the previous Integer object reference. So it is impossible to change an integer( of any kind) by passing it into a method. You HAVE to assign it in its original scope.

classic n00b mistake. Thanks ra4king (and lhkbob). The problem was runEffect() in Attack's subclasses. They all had an undefined method in them, which made them unusable by the compiler so it went up to the parent class version which was abstract hence, the AbstractMethodError.

I use JCreator, because my first professor used it and I've grown accustomed to it. Eclipse and netbeans both take extremely long to startup and I don't consider myself in need of their advanced features just yet. Everytime I build a project in JCreator, it saves all of the files that are open in JCreator. I thought it compiled them as well, but lesson learned. Thanks everybody.

EDIT: I understand the concept behind what is going on... if the method were

Monster.attack( SwordSlash, Monster )

then this would work fine. The idea I'm missing is why even bother using an Attack parameter if I can't use its subclasses methods.

There isn't much to the stack trace...

It's a runtime error( sorry, I should have mentioned that. In my head it was a compiler error ). The runtime error occurs when the program comes across nonstatic Monster.attack( Attack, Monster ).

The Battle class essentially accepts two Monsters and loops them through a series of attacks until one's health is 0. The battle loop is currently in the constructor of the Battle class... bad, I know.

Quote

Exception in thread "main" java.lang.AbstractMethodError: Attack.runEffect(LMonster;)V at Monster.attack(Monster.java:194) at Battle.<init>(Battle.java:62) at Battle.main(Battle.java:127)

class Attack is an abstract class. It has MANY subclasses( so far about 10, planned to exponentiate ). The idea is, that attacks cause damage( or don't ), and also have some other effect in the battle such as raising its own attack power or lowering an enemy's defense power. So, class Attack has an abstract method called runEffect( ), which each subclass is forced to override.

For example,

1 2

Monsterm = newMonster( );m.attack( newSwordSlash( ), badGuy );

SwordSlash not only does damage, but with a 50% chance it can also lower the target's defense. So its runEffect() method runs the math, if the Monster is lucky, he lowers his target's defense.

I understand the error. SwordSlash is being demoted to just an Attack, and a.runEffect( ) is trying to use the runEffect( ) method in Attack which is abstract, hence the error. The question is what now? I don't want to write a different attack( ) method for each subclass of Attack.

Hello, I'm a programming student and one of my exercise examples was to animate a car to drive across the screen. Done. Then I wanted to get creative and have the user hold a key to accelerate the car, and then when they let go, have the car slow to a stop. Sadly, I cannot get this to work. Incorporating the KeyListener into the Timer has proven too challenging for me. I would appreciate any help.

I understand that many of these practices aren't the best. I SHOULD have built a Car class, but the exercise called for drawing Graphics class shapes to make car, and I've been building on that... This could also work supposedly with an Image object.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org