通过比较其参数之一获取对象

问题描述 投票:0回答:1

我正在从事图书馆项目;有一个图书馆课:

public Library(int id, String libName, String libAddress, double libBudget, boolean libEnabled)

和图书馆员班:

Public Librarian(int id, String firstname,String surname,
    String email, String nss, String password, int role, int library, boolean enabledLibrarian)

每个图书馆员都被分配到一个图书馆:

Librarian.getLibrary(int x);

项目范围需要管理多个库,所以我有一个控制器,它会在开始时生成我的库列表

 public static List<Library> libraries()

[购买书籍,批准贷款等方法都在Library()类下。我不确定该怎么做才能获取对象Library()的实例,其中Library()的参数等于Librarian()-]中相应参数的实例

     private static void LibrarianLanding(Librarian librarian, Library library) {
    System.out.println("Welcome, " + librarian.getFirstname() + " " + librarian.getSurname());
    System.out.println("You are in the Admin area of Library No." + librarian.getLibrary());

    Library library = libraries.get() //WHERE library.getID() == Librarian.getLibrary();
    library.PurchaseSomeBooks(librarian); 

也许它很简单,我想念。

我正在从事图书馆项目;有一个Library类:public Library(int id,String libName,String libAddress,double libBudget,boolean libEnabled)和一个Librarian类:Public Librarian(...

java jdbc
1个回答
0
投票

如果您将库列表更改为以库ID为键的库地图,如下所示:

© www.soinside.com 2019 - 2024. All rights reserved.