wood burning stoves*
The moose likes Beginning Java and the fly likes Very new and confused Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Very new and confused" Watch "Very new and confused" New topic
Author

Very new and confused

Vlada Den
Ranch Hand

Joined: Dec 19, 2004
Posts: 32
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

Joined: Jul 22, 2000
Posts: 9044
    
  10
Can you give an example of a Catagory?

I think you probably do not want to have String catagory in the constructor.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Vlada Den
Ranch Hand

Joined: Dec 19, 2004
Posts: 32
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

Joined: Jul 22, 2000
Posts: 9044
    
  10

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Very new and confused
 
Similar Threads
Chain of Responsibility Pattern
Please help!!!
Chain of Responsibility Pattern
SQL Results
Reference a Non-static interface in a static Method