• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very new and confused

 
Vlada Den
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am very new to Java. Could you, please, help me out with the following code:

public class Librarian extends User {
private String category;

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

public String getCategory() {
return category;
}

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

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

The class Librarian should be changed to reflect the situation where a librarian should be able to be associated with a list of categories (each category is still registered as a String).

My code may not be perfect, too

Please, help!

Thanks a lot,

Vlada
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give an example of a Catagory?

I think you probably do not want to have String catagory in the constructor.
 
Vlada Den
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply!

Category is a String holding the book-category in which the librarian is considered an expert. But librarians are often experts in more than one book-category. So how to implement this. I guess, it's something to do with an array list.

Vlada
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rather than a member variable of type String named catagory, I suggest you use a private member variable of type ArrayList named catagory. You can store the Strings in the ArrayList.

Also remember to remove it from the constructor.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic