您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Written by : Bin Hong Lee
  3. * Last edited : 6/6/2016
  4. */
  5. import java.util.*;
  6. class User
  7. {
  8. private String name;
  9. private int id;
  10. private int limit;
  11. private List<Integer> books = new ArrayList<Integer>();
  12. public User(String name, int id, int limit)
  13. {
  14. this.name = name;
  15. this.id = id;
  16. this.limit = limit;
  17. }
  18. public String getName()
  19. {
  20. return name;
  21. }
  22. public int getId()
  23. {
  24. return id;
  25. }
  26. public void setName()
  27. {
  28. this.name = name;
  29. }
  30. public boolean status()
  31. {
  32. if (books.size() < limit)
  33. {
  34. return true;
  35. }
  36. return false;
  37. }
  38. public List<Integer> bookStatus()
  39. {
  40. return books;
  41. }
  42. public boolean borrowNewBook(int id)
  43. {
  44. if (status())
  45. {
  46. books.add(id);
  47. return true;
  48. }
  49. else
  50. {
  51. return false;
  52. }
  53. }
  54. public boolean returnBook(int id)
  55. {
  56. for (int i = 0; i < books.size(); i++)
  57. {
  58. if (books.get(i) == id)
  59. {
  60. books.remove(i);
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. }