我有3个名为Library,Customer和Catalog的类。我在Netbeans上做这个代码。
这是我的图书馆类
public class Library {
private Catalogue catalogue;
private List<Customer> customers;
public static void main(String[] args) {
Library library = new Library();
}
public Library() {
catalogue = new Catalogue(this);
customers = new LinkedList<Customer>();
}
}
这是我的目录类
public class Catalogue {
private Library library;
public Catalogue(Library library) {
this.library = library;
}
}
这是我的客户类
public class Customer {
private int ID;
private String name;
private int balance;
public Customer(int ID, String name, int balance) {
this.ID = ID;
this.name = name;
this.balance = balance;
}
}
如上面的示例代码所示,我可以直接从库中调用客户,但我的问题是如何从Catalog中调用customer。 限制是我无法在目录中添加Customer字段,也无法在库中添加任何Customer字段。
基于上面的例子,我必须从目录中呼叫客户。
由于
答案 0 :(得分:0)
你必须通过图书馆。在库中添加一个调用Customer的方法,并在Catalog中使用该方法。