Results 1 to 17 of 17
  1. #1
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default Hw Holiday Prac..Happy Turkey Day.

    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.




    Java Code:
    public abstract class FictChars {
    	protected String name,moves,weakness;
    	
    	
    	
    	protected abstract void fight();
    
    
    }

    Java Code:
    public class WonderWoman extends FictChars {
    
    	String name = "Wonder Woman";
    	String moves = "Wondrous Spin";
    	String weakness = "Street Fighters";
    
    	public void fight() {
    		System.out.println("4 Wondrous Spins!!!!YOUR OUT!!!");
    	
    	}
    	public void setName(String ne){
    		name = ne;
    		} 
    	
    	
    	
    	
    	public String toString() {
    	return ("Hay all my name is" + name +"My Special move is " + moves + "Weaknesses are -->" + weakness);
    	}
    		
    
    }
    // tried to create a new wonderwoman object to try and call my methods . to see if they worked like
    Java Code:
    FictChars WonderWoman = new FictChars();
                WonderWoman.fight();// identifier expected error

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Java Code:
    FictChars WonderWoman = new FictChars();
                WonderWoman.fight();// identifier expected error
    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.

  3. #3
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    so how i interpret what your saying is something like.
    Java Code:
    WonderWoman alex = new WonderWoman();
              alex.fight();//// I tried this also and got an identifier error also

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Bgreen7887 View Post
    so how i interpret what your saying is something like.
    Java 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:

    Java Code:
    AbstractType myVar = new DerivedType();
    myVar.overriddenMethod();
    As for your error, please show the full code and the full error message.

  5. #5
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

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

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Bgreen7887 View Post
    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?

  7. #7
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

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

    Java 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.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  9. #9
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    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

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Bgreen7887 View Post
    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. #11
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    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.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Bgreen7887 View Post
    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.

  13. #13
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

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

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Bgreen7887 View Post
    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.

  15. #15
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    i need guidance how to spruce this up a little
    Java Code:
    public class WonderWoman extends FictChars {
    
    	String name = "Wonder Woman";
    	String finishMove = "Wondrous Spin";
    	String weakness = "Street Fighters";
    
    	public void fight() {
    		System.out.println("4 Wondrous Spins!!!!YOUR OUT!!!");
    	
    	}
    		public void flyKick(){
    		System.out.println("3 Grusome RoundHouses ");
    
    	}
    		public void whipSlap() {
    	System.out.println("Ouuch Thats Tough leather");
    	}
    		public void redWhiteBluePunch() {
    	System.out.println("AN ALL AMERICAN LEFT HOOK!!!");
    	}
    
    	
    }

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  17. #17
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

Similar Threads

  1. Happy New Year
    By sanjeevtarar in forum Entertainment
    Replies: 7
    Last Post: 12-14-2011, 06:12 AM
  2. Wishing a very Happy New Year
    By CJSLMAN in forum Forum Lobby
    Replies: 4
    Last Post: 01-05-2009, 06:38 AM
  3. Happy Bijoya!
    By playwin2 in forum Forum Lobby
    Replies: 1
    Last Post: 11-16-2008, 10:24 PM
  4. Happy B'day Eranga
    By sanjeevtarar in forum Forum Lobby
    Replies: 13
    Last Post: 04-18-2008, 04:39 AM
  5. i'm happy to join this forum
    By sivasayanth in forum Introductions
    Replies: 1
    Last Post: 12-25-2007, 09:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •