Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help!!!

 
Vlada Den
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Can't seem to manage the following code:

public class Expert extends User {
private String category;
private int categoryIndex;

public Expert(String aName, int aUserID,
String aTelephoneNo, String category) {
super(aName, aUserID, aTelephoneNo);
this.category = category;
}

private List categoryList = new ArrayList();


public String getCategory(int categoryIndex) {
String empty = "";
for (int i = 0; i < categoryList.size(); i++) {
if(i==categoryIndex) {
empty = "" + categoryList.get(i);
}
}
return empty;
}

public void setCategory(String category) {
this.category = category;
}

public String toString() {
return super.toString() + "\tCategory: " + category;
}
}

Any help would be greatly appreciated.
Thanks!
 
tanja klaut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi vlada den,

where is the problem? what do you want the class to do that it is not doing or what is it doing wrongly?
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vlada Den:
Can't seem to manage the following code:
...
Any help would be greatly appreciated.
Thanks!


How are you trying to "manage" it? Do you mean you don't know how to create an application from it? You'd need a main() method.

Are you getting compilation errors? What are they?

Can you compile but get runtime errors? What happens?

Do you get an Exception? What is it?
[ January 30, 2005: Message edited by: Marilyn de Queiroz ]
 
Vlada Den
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing it in NetBeans, so the main method will be added, when I create A GUI. I get a compilation error in this line:

private List categoryList = new ArrayList();

Can't find out what's wrong here.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vlada Den:
I get a compilation error in this line:

private List categoryList = new ArrayList();
I'm going to guess (please don't make us guess!) that the errors you're getting areIf so, this is telling you that your Expert class doesn't define List and ArrayList.

If a class needs to use another class, it must import it. Import statements tell the compiler where to find the definition for another class that you want to use. They go at the top of the file after the package statement (if any) and before the class or interface definitions. They look like this:Your job is to find where the List and ArrayList classes are located. If you don't know, use the JavaDocs to find out.
[ January 30, 2005: Message edited by: David Harkness ]
 
Vlada Den
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I see...
Thank you so much, David.
And I'll try to ask more to-the-point questions next time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic