Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 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 (Jonah Broyer)
  7.  * @version (1/18/2020)
  8.  */
  9. class Book
  10. {
  11.     // The fields.
  12.     private String author;
  13.     private String title;
  14.     private int pages;
  15.  
  16.     /**
  17.      * Set the author and title fields when this object
  18.      * is constructed.
  19.      */
  20.     public Book(String bookAuthor, String bookTitle, int bookPages)
  21.     {
  22.         author = bookAuthor;
  23.         title = bookTitle;
  24.         pages = bookPages;
  25.     }
  26.  
  27.     /**
  28.      * Exercise 2.83
  29.      * Return the author of the book.
  30.      */
  31.     public String getAuthor()
  32.     {
  33.         return author;
  34.     }
  35.    
  36.     /**
  37.      * Exercise 2.83
  38.      * Return the title of the book.
  39.      */
  40.     public String getTitle()
  41.     {
  42.         return title;
  43.     }
  44.    
  45.     /**
  46.      * Exercise 2.84
  47.      * Print the author's name.
  48.      */
  49.     public void printAuthor()
  50.     {
  51.         System.out.println("Author: " + author);
  52.     }
  53.    
  54.     /**
  55.      * Exercise 2.84
  56.      * Print the title of the book.
  57.      */
  58.     public void printTitle()
  59.     {
  60.         System.out.println("Title: " + title);
  61.     }
  62.    
  63.     /**
  64.      * Exercise 2.85
  65.      * Return the number of pages.
  66.      */
  67.     public int getPages()
  68.     {
  69.         return pages;
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement