the second Objects lab.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 (Insert your name here.)
  7. * @version (Insert today’s date here.)
  8. */
  9. public class Book
  10. {
  11. // The fields.
  12. private String author;
  13. private String title;
  14. private int pages;
  15. private String refNumber;
  16. private int borrowed;
  17. /**
  18. * Set the author and title fields when this object
  19. * is constructed.
  20. */
  21. public Book(String bookAuthor, String bookTitle, int bookPages)
  22. {
  23. author = bookAuthor;
  24. title = bookTitle;
  25. pages = bookPages;
  26. refNumber = "";
  27. }
  28. public void printAuthor(){
  29. System.out.println(author);
  30. }
  31. public void printTitle(){
  32. System.out.println(title);
  33. }
  34. public int getPages(){
  35. return pages;
  36. }
  37. public void setRefNumber(String ref){
  38. if(ref.length()>=3){
  39. refNumber = ref;
  40. } else {
  41. System.out.print("enter a ref of 3 or more characters");
  42. }
  43. }
  44. public int getBorrowed(){
  45. return borrowed;
  46. }
  47. public void setBorrowed(String ref){
  48. borrowed += 1;
  49. }
  50. public String getRefNumber(){
  51. return refNumber;
  52. }
  53. public void printDetails(){
  54. System.out.println("Title: " + title + ", Author: " + author + ", Pages: " + pages + ", Checkouts: " + borrowed);
  55. }
  56. }