From 95d4f4fbdd8d613d95baf2479fff1d15135b50c6 Mon Sep 17 00:00:00 2001 From: BinHong Lee Date: Mon, 6 Jun 2016 23:45:25 -0700 Subject: [PATCH] bookStatus(), returnBook(int) - Added bookStatus() that will help main program to determine if the books are not past due - Added returnBook(int) to remove the returned book from the List - Fixed List as List - Added import java.util.* for List and ArrayList - Fixed status with status() --- User.java | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/User.java b/User.java index 42edc7a..8e73f6c 100644 --- a/User.java +++ b/User.java @@ -3,12 +3,14 @@ * Last edited : 6/4/2016 */ + import java.util.*; + class User { private String name; private int id; private int limit; - private List books = new ArrayList(); + private List books = new ArrayList(); public User(String name, int id, int limit) { @@ -31,18 +33,20 @@ class User { if (books.size() < limit) { - if (bookStatus) - { - return true; - } + return true; } return false; } + public List bookStatus() + { + return books; + } + public boolean borrowNewBook(int id) { - if (status) + if (status()) { books.add(id); return true; @@ -52,4 +56,18 @@ class User return false; } } + + public boolean returnBook(int id) + { + for (int i = 0; i < books.size(); i++) + { + if (books.get(i) == id) + { + books.remove(i); + return true; + } + } + + return false; + } }