Public paste
Book
By: Guest | Date: Apr 11 2009 19:59 | Format: None | Expires: never | Size: 3.14 KB | Hits: 839

  1. import java.util.Date;
  2. import java.text.SimpleDateFormat;
  3. import java.text.NumberFormat;
  4.  
  5.  
  6.  
  7.  
  8. /**
  9.  *
  10.  * This class will define what is the book and what is in the book, essentially its the book it self.
  11.  *
  12.  */
  13.  
  14. public class Book
  15. {
  16.                  /////////////////////////////////////////////
  17.            //            Member Variables             //
  18.      /////////////////////////////////////////////
  19.  
  20.         private String bookTitle;
  21.         private String bookAuthor;
  22.         private double bookPrice;
  23.         private String bookPublisher;
  24.         private Date bookCopyright;
  25.        
  26.                  /////////////////////////////////////////////
  27.            //              Constructors               //
  28.      /////////////////////////////////////////////
  29.         /**
  30.     * Class constructor.
  31.     */
  32.         public Book()
  33.         {
  34.                 bookTitle = "test";
  35.                 bookAuthor = "Blake";
  36.                 bookPrice = 0;
  37.                 bookPublisher = "Marvel";
  38.                 bookCopyright = new Date();
  39.         }
  40.         /**
  41.     * Class constructor specifying the different parameters that it takes.
  42.          * @param title this is the title of the book.
  43.          * @param author this is the author of the book.
  44.          *      @param price this is the cost of the book.
  45.          * @param publisher this is the publisher of the book.
  46.          *      @param copyright this is the date the book was copyrighted.
  47.     */
  48.         public Book(String title, String author, double price, String publisher, Date copyright)
  49.         {
  50.                 bookTitle = title;
  51.                 bookAuthor = author;
  52.                 bookPrice = price;
  53.                 bookPublisher = publisher;
  54.                 bookCopyright = copyright;
  55.         }
  56.                 /////////////////////////////////////////////
  57.           //                 Methods                 //
  58.     /////////////////////////////////////////////
  59.        
  60.          /**
  61.      * Gets the book title.
  62.      *
  63.      *
  64.           * @return this returns the book title once it is found.
  65.      */
  66.         public String getBookTitle()
  67.         {
  68.                 return(bookTitle);
  69.         }
  70.          
  71.          /**
  72.      * Gets the the books author name.
  73.      *
  74.      *  
  75.           * @return this returns the author of the book being called.
  76.      */
  77.  
  78.         public String getBookAuthor()
  79.         {
  80.                 return(bookAuthor);
  81.         }
  82.        
  83.          /**
  84.      * Gets the books price.
  85.      *
  86.      *  
  87.           * @return this returns the books price when called.
  88.      */
  89.  
  90.         public double getBookPrice()
  91.         {
  92.                 return(bookPrice);
  93.         }
  94.        
  95.          /**
  96.      * Gets the books publisher.
  97.      *
  98.      *  
  99.           * @return this returns the books publisher when called.
  100.      */
  101.  
  102.         public String getBookPublisher()
  103.         {
  104.                 return(bookPublisher);
  105.         }
  106.        
  107.          /**
  108.      * Gets the books copyright date.
  109.      *
  110.      *  
  111.           * @return this returns the books year of copyright.
  112.      */
  113.  
  114.         public Date getCopyRight()
  115.         {
  116.                
  117.                 return(bookCopyright);
  118.         }
  119.        
  120.          /**
  121.      * toString, overwritten from original prints things nicely.
  122.      *
  123.      *  
  124.           * @return this returns the book title, the author, the price, the publisher and the copyright date..
  125.      */
  126.  
  127.         public String toString()
  128.        
  129.         {
  130.                 SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
  131.                 NumberFormat currency = NumberFormat.getCurrencyInstance();
  132.        
  133.  
  134.                 return("Book Title: " + bookTitle + " Book Author: " + bookAuthor + " Book Price: " + currency.format(bookPrice) + " Book Publisher: " + bookPublisher + " Book CopyRight Date: " + formatter.format(bookCopyright));
  135.                                 }
  136. }