Advertisement
rmword

Untitled

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