I am working on a project given to me for classwork and we are modifying a library system that allows one to addpatrons to the library system, addbooks is already done for me and i have used that as a template to create addpatrons. I have completed it but whenever im trying to create it i get the following error.
IndexOutOfBoundsException: Index -1 out of bounds for length 0
Here is where the code is going wrong.
public void execute(Library library, LocalDate currentDate) throws LibraryException {
int lastIndex = library.getPatrons().size() -1;
int maxId = library.getPatrons().get(lastIndex).getId();
Patron patron = new Patron(++maxId, name, phone);
library.addPatron(patron);
System.out.println("Patron #" + patron.getId() + " added.");
The add patron takes in two values name and phone.
Thanks for your time