Can anyone tell me if im doing doing this correctly so Far pretty please..
Problem 1: Abstract: You are going to write an abstract class called FictionChars which will embrace the following types: SpiderMan, BionicWoman, BatMan, SuperMan, WonderWoman, SixMilDollarMan, and Xmen.

Think about the common as well as distinctive characteristics of each fiction character. Define at least three variables that uniquely describe the common/distinctive characteristics and three methods that utilize them.

For example, SixMilDollarMan can be uniquely defined by three variables: name, surgical implant and the cost of capability ($6 mil) while the methods to demonstrate his characteristics are running(), jumping(), and laserFocusing() and .

* write an abstract class for these fiction characters.
* write classes for these fiction characters.

You can't instantiate an abstract class but instead need to call new on the WonderWoman class. Please give your variable a better name though since you definitely don't want to use a class name for your variable.

11-25-2010, 03:51 PM

Bgreen7887

so how i interpret what your saying is something like.

Code:

WonderWoman alex = new WonderWoman();
alex.fight();//// I tried this also and got an identifier error also

11-25-2010, 03:59 PM

Fubarable

Quote:

Originally Posted by Bgreen7887

so how i interpret what your saying is something like.

Code:

WonderWoman alex = new WonderWoman();
alex.fight();//// I tried this also and got an identifier error also

Close. Since you're trying to learn about abstract types, I would think your prof would want something like:

Code:

AbstractType myVar = new DerivedType();
myVar.overriddenMethod();

As for your error, please show the full code and the full error message.

11-25-2010, 03:59 PM

Bgreen7887

i think the compiler believes my variable is a data type instead of an object??

11-25-2010, 04:03 PM

Fubarable

Quote:

Originally Posted by Bgreen7887

i think the compiler believes my variable is a data type instead of an object??

Again, can we see the actual code and the actual error message?

11-25-2010, 04:08 PM

Bgreen7887

We didnt learn anything about abstracttype or anything. this is what i have

Code:

public class Loud {
WonderWoman nina = new WonderWoman();

nina.fight();
}

java:4: <identifier> expected
nina.fight();
^
1 error

----jGRASP wedge2: exit code for process is 1.

11-25-2010, 04:10 PM

Fubarable

This has nothing to do with abstract or derived types and all to do with your trying to call methods outside of a method block or constructor block. Consider giving Loud a main method and calling stuff that needs to be called in a method in there. Also, again, I think you should declare nina as the base type -- the abstract type, and intantiate (call new on), the derived type, the class that extends the base type.

11-25-2010, 04:15 PM

Bgreen7887

i literally just slapped myself.Im creating so many diff classes that it completely blew my mind that i had no main method and thats suppose to be the driver. it compiles now

11-25-2010, 04:18 PM

Fubarable

Quote:

Originally Posted by Bgreen7887

i literally just slapped myself.Im creating so many diff classes that it completely blew my mind that i had no main method and thats suppose to be the driver. it compiles now

Great! Now make sure you declare nina as a FictChars variable and then call new with the WonderWoman constructor.

11-25-2010, 04:21 PM

Bgreen7887

one more ? fubarable as you are most helpful.. i have give 3 unique methods to demostrate her capablity..for instance if i wanted one of the methods say
// public void teleport()
or anything like that...what could i fill the method body with..like what actions could calling this method really do besides print a string to the screen.

11-25-2010, 04:29 PM

Fubarable

Quote:

Originally Posted by Bgreen7887

one more ? fubarable as you are most helpful.. i have give 3 unique methods to demostrate her capablity..for instance if i wanted one of the methods say
// public void teleport()
or anything like that...what could i fill the method body with..like what actions could calling this method really do besides print a string to the screen.

Hm, I'm not sure how to answer this question, other than that the method could do anything you want it to do really.

For instance if you do any Swing programming, you will often create classes that implement ActionListener, and as you've may have discovered, the code in there can do many different wondrous things. While I'm describing here the implementation of an interface rather than the extension of an abstract class, the concepts are the same.

11-25-2010, 04:35 PM

Bgreen7887

lol thanks for the tough luv, can you give me an example of a method like that plzzz

11-25-2010, 04:38 PM

Fubarable

Quote:

Originally Posted by Bgreen7887

lol thanks for the tough luv, can you give me an example of a method like that plzzz

I'm still not 100% sure of what you're asking. If you want a method to do more than output println statements, then you'll need to make a more complex class, one that has fields and behaviors. Though for your little app, I see nothing wrong with println statements, and perhaps throwing in a for loop with Thread.sleep(...) thrown in for variety.

I assume that the abstract class only has one method -- fight, correct? If so, then I would have my fight class call a bunch of the specific fighting methods, perhaps separated by Thread.sleep(1000), again you can do this in a for loop to have her give the opponent a bunch of whipSlaps, r-w-b-punches, kicks, whatever, and at the end print out, "opponent crushed" or something like that.