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;
- /**
- * Set the author and title fields when this object
- * is constructed.
- */
- public Book(String bookAuthor, String bookTitle, int bookPages)
- {
- author = bookAuthor;
- title = bookTitle;
- pages = bookPages;
- }
- /**
- * 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement