Advertisement
rmword

Untitled

Sep 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 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.  
  18. /**
  19. * Set the author and title fields when this object
  20. * is constructed.
  21. */
  22. public Book(String bookAuthor, String bookTitle, String bookrefNumber, int bookPages, int bookBorrowed)
  23. {
  24. author = bookAuthor;
  25. title = bookTitle;
  26. pages = bookPages;
  27. refNumber = "";
  28. borrowed = bookBorrowed;
  29. }
  30.  
  31. public String getAuthor()
  32. {
  33. return author;
  34. }
  35.  
  36. public String getTitle()
  37. {
  38. return title;
  39. }
  40. public int getPages()
  41. {
  42. return pages;
  43. }
  44. public String getRefNumber()
  45. {
  46. return refNumber;
  47. }
  48. public int getBorrowed()
  49. {
  50. return borrowed;
  51. }
  52. public void bookBorrowed()
  53. {
  54. borrowed++;
  55. }
  56. public void setRefNumber(String refNumber)
  57. {
  58. if(refNumber.length()<3) System.out.println("Reference Number has to be at least three characters!");
  59. else this.refNumber = refNumber;
  60. }
  61. public void printAuthor()
  62. {
  63. System.out.println(author);
  64. }
  65. public void printTitle()
  66. {
  67. System.out.println(title);
  68. }
  69. public void printDetails()
  70. {
  71. String refNumPrint = refNumber;
  72. System.out.println("Title: " + title + ",Author: " + author + ",Pages: " + pages);
  73. if(refNumPrint.length() < 0)
  74. {
  75. refNumPrint = "ZZZ";
  76. }
  77. System.out.println("Reference number: " + refNumPrint);
  78. System.out.println("Borrowed : " + borrowed);
  79. }
  80.  
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement