/* * ================================================================= * Book.java: Create a book object with an association to a customer * ================================================================= */ public class Book { // Data attributes private String name; private String author; // Set relationship .... private Customer owner; // Constructor public Book () { this.owner = null; } // String representations ... public String toString() { String s = "Book name: " + getName() + "\n" + " author: " + getAuthor() + "\n"; if (this.owner != null ) s += " owned by: " + owner.getName() + "\n"; return s; } // Set and access attributes public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } // Association accessor methods ... public Customer getCustomer() { return owner; } public void setCustomer( Customer owner ) { if (owner != null) this.owner = owner; } }