Results 1 to 19 of 19
Thread: Need help with Interface
- 12-14-2010, 01:14 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
Need help with Interface
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.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"; } } ____________________________
- 12-14-2010, 01:17 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 12-14-2010, 01:22 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
Oh sorry here it is. i need to print the Extra()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 ("-----------------------------------"); } } }
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
-----------------------------------
- 12-14-2010, 01:32 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In heroes class I can see that you've refereed many classes to add into arrays. Did you define them all?
- 12-14-2010, 01:34 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
Yes i did and Bionic woman was one of them. they all go the same way.
- 12-14-2010, 01:44 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Then where you stuck with?
If you want to add additional details to the print statements you can have multiples.
- 12-14-2010, 01:46 AM #7
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
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 :(
- 12-14-2010, 01:59 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If this is the main class, to work on you've to define the execution point, that is the main method.
- 12-14-2010, 02:01 AM #9
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
i think i should re write the Fiction chars but keep it completely empty.Java Code:public class TheGroup{ public static void main (String[] args) { heroes G = new heroes(); G.Extra(); } }
- 12-14-2010, 02:03 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Means that in constructor the list is not manipulated properly.
- 12-14-2010, 02:10 AM #11
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
this are the errors i got.. Help plzJava Code:FictionChars.java:7: <identifier> expected public FictionChars (String eName, String ername, String ePower) ^
- 12-14-2010, 09:10 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Could you post the complete constructor implementation.
- 12-14-2010, 09:13 AM #13
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
I did that FictionChars is my constructor
- 12-14-2010, 09:16 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yeah, somewhere you've done a mistake, seem that defining an identifier in a wrong way, or invalid reference.
- 12-14-2010, 09:26 AM #15
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
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.
- 12-14-2010, 09:26 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 12-14-2010, 09:35 AM #17
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Last edited by Eranga; 12-14-2010 at 09:47 AM.
- 12-14-2010, 09:38 AM #18
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
so should i just put it as :
Java Code:interface FictionChars { public FictionChars (String eName, String ername, String ePower) { } public interface String extraAb(); }
- 12-14-2010, 09:47 AM #19
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
No, it's something like this.
You haven't define the return type. You misses the return type and that's why it's complain.Java Code:interface FictionChars { public void FictionChars (String eName, String ername, String ePower); }
Similar Threads
-
Why INTERFACE...pls tell me please....
By rohitjava in forum New To JavaReplies: 3Last Post: 09-02-2010, 10:27 AM -
what is the need of interface?
By makpandian in forum New To JavaReplies: 1Last Post: 03-13-2009, 10:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks