We have two classes person and dog person object acts as an owner for dog and dog acts as pet for the person i.e a bidierctional association i have done this (see code) i modify the person class so that the person object can act for an owner for up to 20 dogs. Where im a bit lost is creating a test with main method to test if it works
DOG
/** * Write a description of class Dog here. * * @author (your name) * @version (a version number or a date) */ public class Dog { private String name; private int age; /**added for part c to create the * bidirectional association between dog Object and person object */ private Person owner; public Dog(String name,int age) { setName(name); setAge(age); } public void setName(String name) { this.name=name; } public void setAge(int age) { this.age=age; } /**added for part c to create the * bidirectional association between dog Object and person object */ public void setPerson(Person owner) { this.owner=owner; } public String getName() { return name; } public int getAge() { return age; } /**added for part c to create the * bidirectional association between dog Object and person object */ public Person getPerson() { return owner; } public String toString() { return getName() +" "+ getAge(); } public void print() { System.out.println(toString()); } }
PERSON
/** * Write a description of class Dog here. * * @author (your name) * @version (a version number or a date) */ public class Person { private String name; private String address; private int age; Dog dog[] = new Dog[20]; /**added for part c to create the * bidirectional association between dog Object and person object */ private Dog pet; public Person(String name,String address,int age) { setName(name); setAddress(address); setAge(age); } public void setName(String name) { this.name=name; } public void setAddress(String address) { this.address=address; } public void setAge(int age) { this.age=age; } /**added for part c to create the * bidirectional association between dog Object and person object */ public void setDog(Dog pet) { this.pet=pet; } public String getName() { return name; } public int getAge() { return age; } public String getAddress() { return address; } /**added for part c to create the * bidirectional association between dog Object and person object */ public Dog getDog() { return pet; } public String toString() { return getName() +" "+ getAge()+" "+ getAddress()+ getDog(); } public void print() { System.out.println(toString()); } }
my attempt at test