Results 1 to 4 of 4
Thread: relation doesnt work
- 03-12-2011, 04:14 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
- 03-12-2011, 04:31 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
What about this:
After both objects are created you have to set one as a member in the other (and vice versa).Java Code:public class Owner { private Pet pet; public void setPet(Pet pet) { this.pet= pet; } public Pet getPet() { return pet; } } public class Pet { private Owner owner; public void setOwner(Owner owner) { this.owner= owner; } pubic Owner getOwner() { return owner; } }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-12-2011, 06:04 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
thank you for your replie, I tried what you said and i didnt get any error messages but neither did I get Waht i wanted it's probably my fault so I'll give you my code it's partly dutch i'll put the translation next to it
public class Eigenaar owner
{
private String naamEig; nameOwn
private String geslacht; sex
private int leeftijd; age
and
public class Huisdier pet
{
private String naam ; name
private String soort ; breed
private int leeftijd age
private String eigenaarH; ownerP
private Eigenaar eigenaar; owner (the line you said to add)
public Eigenaar getEigenaar()
{ 3x owner
return eigenaar;
}
so when i execute this methode iwant to get the 3 fields of the owner age sex and name
i already have a setter i think its correct is works when i test is so..
just in case :
public void kenEigenaarToe(String nieuweEigenaar) =( set owner (string newOnwer))
{
eigenaarH = nieuweEigenaar;
}
I would greatly appreciate any help
- 03-12-2011, 07:02 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
In my terminology (classes) two objects can be linked together as:
kind regards,Java Code:Pet fifi= new Pet( ... ); // a new Pet Owner rambo= new Owner( ... ); // a new Owner ... fifi.setOwner(rambo); //link the two objects rambo.setPet(fifi); ... fifi.getOwner(); // returns rambo rambo.getPet(); // returns fifi
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
KeyListener doesnt work some times.
By Addez in forum New To JavaReplies: 15Last Post: 09-21-2010, 04:25 PM -
PrintWriter doesnt work :(
By Addez in forum New To JavaReplies: 11Last Post: 01-17-2010, 05:59 PM -
why doesnt my insertion sort method not work?
By Jeremy8 in forum New To JavaReplies: 7Last Post: 11-15-2009, 02:56 AM -
Dll Call doesnt work
By INFACT in forum New To JavaReplies: 1Last Post: 10-04-2009, 09:31 PM -
java doesnt allow vista to work
By 10rosas in forum New To JavaReplies: 5Last Post: 12-22-2008, 04:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks