Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 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.  
  15.     /**
  16.      * Set the author and title fields when this object
  17.      * is constructed.
  18.      */
  19.     public Book(String bookAuthor, String bookTitle)
  20.     {
  21.         author = bookAuthor;
  22.         title = bookTitle;
  23.     }
  24.  
  25.     /**
  26.      * Exercise 2.83
  27.      * Return the author of the book.
  28.      */
  29.     public String getAuthor()
  30.     {
  31.         return author;
  32.     }
  33.    
  34.     /**
  35.      * Exercise 2.83
  36.      * Return the title of the book.
  37.      */
  38.     public String getTitle()
  39.     {
  40.         return title;
  41.     }
  42.    
  43.     /**
  44.      * Exercise 2.84
  45.      * Print the author's name.
  46.      */
  47.     public void printAuthor()
  48.     {
  49.         System.out.println("Author: " + author);
  50.     }
  51.    
  52.     /**
  53.      * Exercise 2.84
  54.      * Print the title of the book.
  55.      */
  56.     public void printTitle()
  57.     {
  58.         System.out.println("Title: " + title);
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement