Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A class that maintains information on a book.
- * This might form part of a larger application such
- * as a library system, for instance.
- *
- * @author (Jonah Broyer)
- * @version (1/18/2020)
- */
- class Book
- {
- // The fields.
- private String author;
- private String title;
- private int pages;
- private String refNumber;
- private int borrowed;
- private boolean courseText;
- /**
- * Set the author and title fields when this object
- * is constructed.
- */
- public Book(String bookAuthor, String bookTitle, int bookPages, boolean bookText)
- {
- author = bookAuthor;
- title = bookTitle;
- pages = bookPages;
- refNumber = "";
- courseText = bookText;
- }
- /**
- * Exercise 2.83
- * Return the author of the book.
- */
- public String getAuthor()
- {
- return author;
- }
- /**
- * Exercise 2.83
- * Return the title of the book.
- */
- public String getTitle()
- {
- return title;
- }
- /**
- * Exercise 2.84
- * Print the author's name.
- */
- public void printAuthor()
- {
- System.out.println("Author: " + author);
- }
- /**
- * Exercise 2.84
- * Print the title of the book.
- */
- public void printTitle()
- {
- System.out.println("Title: " + title);
- }
- /**
- * Exercise 2.85
- * Return the number of pages.
- */
- public int getPages()
- {
- return pages;
- }
- /**
- * Exercise 2.91
- * Print details about the book.
- */
- public void printDetails()
- {
- if(refNumber.length() > 0) {
- System.out.println("Title: " + title + ", Author: " + author +
- ", Pages: " + pages + ", Reference Number: "
- + refNumber + ", Amount of times this book" +
- " has been borrowed: " + borrowed);
- }
- else {
- System.out.println("Title: " + title + ", Author: " + author +
- ", Pages: " + pages + ", Reference Number: "
- + "ZZZ" + ", Amount of times this book has" +
- " been borrowed: " + borrowed);
- }
- }
- /**
- * Exercise 2.90
- * Set the books reference number.
- */
- public void setRefNumber(String ref)
- {
- if(ref.length() >= 3) {
- refNumber = ref;
- }
- else {
- System.out.println("Please enter a reference number that's " +
- "at least three characters.");
- }
- }
- /**
- * Exercise 2.87
- * Return the books reference number.
- */
- public String getRefNumber()
- {
- return refNumber;
- }
- /**
- * Exercise 2.91
- * Update the borrow field.
- */
- public void borrow()
- {
- borrowed = borrowed + 1;
- }
- /**
- * Exercise 2.91
- * Return the value of how many times the book
- * has been borrowed.
- */
- public int getBorrowed()
- {
- return borrowed;
- }
- /**
- * Exercise 2.92
- * Return whether or not the book is being used
- * as a textbook.
- */
- public boolean isCourseText()
- {
- return courseText;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement