Browse Source

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<int> as List<Integer>
- Added import java.util.* for List and ArrayList
- Fixed status with status()
master
BinHong Lee 8 years ago
parent
commit
95d4f4fbdd
1 changed files with 24 additions and 6 deletions
  1. +24
    -6
      User.java

+ 24
- 6
User.java View File

@@ -3,12 +3,14 @@
* Last edited : 6/4/2016 * Last edited : 6/4/2016
*/ */


import java.util.*;

class User class User
{ {
private String name; private String name;
private int id; private int id;
private int limit; private int limit;
private List<int> books = new ArrayList<int>();
private List<Integer> books = new ArrayList<Integer>();


public User(String name, int id, int limit) public User(String name, int id, int limit)
{ {
@@ -31,18 +33,20 @@ class User
{ {
if (books.size() < limit) if (books.size() < limit)
{ {
if (bookStatus)
{
return true;
}
return true;
} }


return false; return false;
} }


public List<Integer> bookStatus()
{
return books;
}

public boolean borrowNewBook(int id) public boolean borrowNewBook(int id)
{ {
if (status)
if (status())
{ {
books.add(id); books.add(id);
return true; return true;
@@ -52,4 +56,18 @@ class User
return false; 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;
}
} }

Loading…
Cancel
Save