LettuceCookie

Book Class File Ver.3

Dec 15th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package finalprogrambook;
  7.  
  8.  
  9. /**
  10.  *
  11.  * @author StoneBoneThone
  12.  *
  13.  */
  14. public class Book
  15. {
  16.   //These are the fields for this class
  17.     //Maybe modify, like modify book year (some might be char)
  18.     private String title;
  19.     private String author;
  20.     private int numberOfPages;
  21.     private String publisherName;
  22.     private int bookYear;
  23.    
  24.     public Book thatBook;
  25.    
  26.    
  27.   //These are the constructors for the class
  28.  //This constructor accepts values for the fields above
  29.    public Book (String theTitle, String theAuthor, int numPages,
  30.            String pubName, int theBookYear)
  31.    {
  32.        theTitle = title;
  33.        author = theAuthor;
  34.        numberOfPages = numPages;
  35.        publisherName = pubName;
  36.        theBookYear = bookYear;
  37.    }
  38.    
  39.  
  40.  //Copy constructor makes a copy of a Book object
  41.     public Book (Book copyBookObject)
  42.     {
  43.         thatBook = copyBookObject.thatBook;
  44.     }
  45.  
  46.    
  47.    
  48.   // These are the methods for the class
  49.  //This method returns the value of title field
  50.     public String getTitle()
  51.     {
  52.         return title;
  53.     }
  54.  
  55.    
  56.  //This method accepts a string argument, assigned to the author field
  57.     public void setAuthor (String setAuthor)
  58.     {
  59.         author = setAuthor;
  60.     }
  61.    
  62.    
  63.  // This method accepts a Book object as arg
  64.  //If arg object has same number of pages as calling object, method returns true
  65.     public boolean hasSameNumPages (Book pageAmount)
  66.     {
  67.       boolean status; //rename
  68.        
  69.         if (numberOfPages == pageAmount.numberOfPages )
  70.             status = true;
  71.         else
  72.             status = false;
  73.                    
  74.        
  75.         return status;
  76.     }
  77.  
  78.    
  79. //This method returns all values of the fields in a friendly, readable fashion
  80.       public String toString()
  81.     {
  82.         String returningString = " The name of the author is " + author + //need setauthor here?
  83.                 ", the number of pages is " + numberOfPages + "." +
  84.                 "\n" + publisherName + "published it in " + bookYear;
  85.      
  86.         return returningString;
  87.     }
  88.  
  89.    
  90. }
Add Comment
Please, Sign In to add comment