Advertisement
rmword

Untitled

Sep 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. /**
  2. * A class that maintains information on a book.
  3. * This might form part of a larger application such
  4. * as a library system, for instance.
  5. *
  6. * @author Rifqi Mukti Wicaksana
  7. * @version 29.09.2017
  8. */
  9. class Book
  10. {
  11. // The fields.
  12. private String author;
  13. private String title;
  14. private String refNumber;
  15. private int pages;
  16. private int borrowed;
  17. public boolean courseText;
  18.  
  19. /**
  20. * Set the author and title fields when this object
  21. * is constructed.
  22. */
  23. public Book(String bookAuthor, String bookTitle, String bookrefNumber, int bookPages, int bookBorrowed)
  24. {
  25. author = bookAuthor;
  26. title = bookTitle;
  27. pages = bookPages;
  28. refNumber = "";
  29. borrowed = bookBorrowed;
  30. }
  31.  
  32. public String getAuthor()
  33. {
  34. return author;
  35. }
  36.  
  37. public String getTitle()
  38. {
  39. return title;
  40. }
  41. public int getPages()
  42. {
  43. return pages;
  44. }
  45. public String getRefNumber()
  46. {
  47. return refNumber;
  48. }
  49. public int getBorrowed()
  50. {
  51. return borrowed;
  52. }
  53. public void bookBorrowed()
  54. {
  55. borrowed++;
  56. }
  57. public boolean isCourseText()
  58. {
  59. return courseText;
  60. }
  61. public void setRefNumber(String refNumber)
  62. {
  63. if(refNumber.length()<3) System.out.println("Reference Number has to be at least three characters!");
  64. else this.refNumber = refNumber;
  65. }
  66. public void printAuthor()
  67. {
  68. System.out.println(author);
  69. }
  70. public void printTitle()
  71. {
  72. System.out.println(title);
  73. }
  74. public void printDetails()
  75. {
  76. String refNumPrint = refNumber;
  77. System.out.println("Title: " + title + ",Author: " + author + ",Pages: " + pages);
  78. if(refNumPrint.length() < 0)
  79. {
  80. refNumPrint = "ZZZ";
  81. }
  82. System.out.println("Reference number: " + refNumPrint);
  83. System.out.println("Borrowed : " + borrowed);
  84. }
  85.  
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement