Results 1 to 19 of 19
  1. #1
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Unhappy Need help with Interface

    Java Code:
    interface FictionChars
    {
    protected String name;
    protected String Realname;
    protected String power;
    
    public FictionChars (String eName, String ername, String ePower)
    {
    name = eName;
    Realname = ername;
    power = ePower;
    }
    
    public String toString()
    {
    String result = "Name: " + name + "\n";
    result += "Realname: " + Realname + "\n";
    result += "Power: " + power;
    return result;
    }
    
    public interface String extraAb();
    }
    _________________________________
    public class Bionicwoman implements FictionChars
    {
    public Bionicwoman (String eName, String ername, String ePower)
    {
    super (eName, ername, ePower);
    }
    public String extraAb()
    {
    return "Amplified hearing in her right ear";
    }
    }
    ____________________________
    I really dont like interface but knowing that my exams soon i need to do my past hws for practice. i got the abstract example which is really similar to this infact i just added interface. so please direct me how to do this one.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    Java Code:
    public class heroes
    {
    private FictionChars[] heroList;
    
    public heroes()
    {
    heroList = new FictionChars[7];
    heroList[0] = new Spiderman ("SpiderMan", "Peter Parker",
    "Able to shoot extremely strong and durable spider-web strings from wrists");
    heroList[1] = new Bionicwoman ("BionicWoman", "Jaime Sommers",
    "A greatly strengthened right arm and enhanced legs");
    heroList[2] = new Batman ("Batman", "Bruce Wayne",
    "High human strength, agility, athleticism and peak conditions");
    heroList[3] = new SuperMan ("SuperMan", "Clark Kent",
    "Superhuman strength, speed, stamina, invulnerability, senses");
    heroList[4] = new WonderWoman ("WonderWoman", "Princess Diana",
    "Superhuman strength, speed, reflexes, stamina, and durability");
    heroList[5] = new SixMilDollarMan ("Six Million Dollar Man", "Steve Austin",
    "His right arm, both legs and the left eye are replaced by bionic implants");
    heroList[6] = new Wolverine ("Wolverine", "Logan",
    "Regenerative healing factor,Retractable adamantium-laced bone claws");
    }
    public void Extra()
    {
    String abilities;
    for (int i=0; i < heroList.length; i++)
    {
    System.out.println (heroList[i]);
    abilities = heroList[i].extraAb();
    System.out.println ("Extra Abilities: " + abilities);
    System.out.println ("-----------------------------------");
    }
    }
    }
    Oh sorry here it is. i need to print the Extra()
    like the name, the real name and power and extra ability.
    in abstract here is the output.
    Name: SpiderMan
    Realname: Peter Parker
    Power: Able to shoot extremely strong and durable spider-web strings from wrists
    Extra Abilities: Ability to cling to most surfaces,Superhuman strength, speed, stamina, agility, reflexes, and durability.
    -----------------------------------
    Name: BionicWoman
    Realname: Jaime Sommers
    Power: A greatly strengthened right arm and enhanced legs
    Extra Abilities: Amplified hearing in her right ear
    -----------------------------------

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In heroes class I can see that you've refereed many classes to add into arrays. Did you define them all?

  5. #5
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    Yes i did and Bionic woman was one of them. they all go the same way.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Then where you stuck with?

    If you want to add additional details to the print statements you can have multiples.

  7. #7
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    the thing is i literally copied the whole thing from abstract method i did then i just put in implements instead of extend lik this one doesnt even work :(

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    If this is the main class, to work on you've to define the execution point, that is the main method.

  9. #9
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    Java Code:
    public class TheGroup{
        public static void main (String[] args)   {
          heroes G = new heroes();
          G.Extra();
       }
    }
    i think i should re write the Fiction chars but keep it completely empty.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  11. #11
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    Java Code:
    FictionChars.java:7: <identifier> expected
    public FictionChars (String eName, String ername, String ePower)
                       ^
    this are the errors i got.. Help plz

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  13. #13
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    I did that FictionChars is my constructor

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yeah, somewhere you've done a mistake, seem that defining an identifier in a wrong way, or invalid reference.

  15. #15
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    yea i figured but i dont know whats wrong though. honestly i hate interface, i understand the basic but when i have to convert from abstract to interface everything goes blank. i tried everything i cant change the constructor cuz well its the constructor and if i change other classes than it will become a interface by itself i think. well i give up i have exam in like 4 hours and i will just go and give it i guess.

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    How I miss that. :(

    Seems to me you don't have any idea about the interfaces lol. How long you deals with these? You have to learn a lot, take a start, I'll help you.

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by karanhs6 View Post
    yea i figured but i dont know whats wrong though. honestly i hate interface, i understand the basic but when i have to convert from abstract to interface everything goes blank. i tried everything i cant change the constructor cuz well its the constructor and if i change other classes than it will become a interface by itself i think. well i give up i have exam in like 4 hours and i will just go and give it i guess.
    First of all properly define the interface. In an interface you must define the return type and no implementations at all.
    Last edited by Eranga; 12-14-2010 at 09:47 AM.

  18. #18
    karanhs6 is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    so should i just put it as :
    Java Code:
    interface FictionChars
    {
    public FictionChars (String eName, String ername, String ePower)
    {
    }
    
    public interface String extraAb();
    }

  19. #19
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    No, it's something like this.

    Java Code:
    interface FictionChars {
    
        public void FictionChars (String eName, String ername, String ePower);
    
    }
    You haven't define the return type. You misses the return type and that's why it's complain.

Similar Threads

  1. Why INTERFACE...pls tell me please....
    By rohitjava in forum New To Java
    Replies: 3
    Last Post: 09-02-2010, 10:27 AM
  2. what is the need of interface?
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 03-13-2009, 10:59 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
  •