Calling a class in another class
I have 2 classes, Event and Dear. I have created Event class with two variables which are Date and Type of Event. This class is known as the ADT Event class.
Another class Dear, has variables name, hphone, email, type of relation and event(which is supposed to be a stack).
How do I write the proper constructors, set and get and toString methods for the event part(highlighted) in the 'Dear' class?
Is the code below correct?
Code:
public Dear(String n, int hp, String e, String t, Stack ev)
{
setData(n, hp, e, t, ev);
}
private void setData(String n, int hp, String e, String t, Stack ev)
{
n = name;
hp = hphone;
e = email;
t = tor;
ev = event;
}
Code:
public Stack getEvent(){
return event;
}
Code:
public String toString()
{
return name + "\t" + hphone + "\t" + email + "\t" + tor "\t" + event;
}
Re: Calling a class in another class
The assignments are back-to-front in the setData method. Also, that code should really go in the constructor - there's little point having a separate private method to do that.
The getEvent method returns a Stack. Is a stack an event? I would have thought the stack is a collection of events.
If I had eight hours to chop down a tree, I would spend 6 hours sharpening an axe...
Anon.
Re: Calling a class in another class
Code:
n = name;
hp = hphone;
e = email;
t = tor;
ev = event;
All of these assignments are the wrong way around. You should be setting 'name' to equal 'n', 'hphone' to equal 'hp' etc.
Edit:
Hi Dave, well you've beaten me to the punch 2 posts in a row - I give in.