All pastes #172456 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-09-16 03:20 UTC
rendered paste body
/**
 * A class that maintains information on a book.
 * This might form part of a larger application such
 * as a library system, for instance.
 *
 * @author Chuck Bates
 * @version 8-12-07
 */
class Book
{
    // The fields.
    private String author;
    private String title;
    private int pages;
    private String reference;
    private int borrowed;
    /**
     * Set the author and title fields when this object
     * is constructed.
     */
    public Book(String bookAuthor, String bookTitle, int bookPages)
    {
        author = bookAuthor; //2.74
        title = bookTitle;   //2.74
        pages = bookPages;   //2.76
        reference = "0";     //2.78
        borrowed = 0;        //2.81
    }
    
    /**
     * this method returns the author of the book
     * 
     * @return the author of the book
     */
    
    public String getAuthor(){
        
        return author; //2.74
    }
    /**
     * this method returns the title of the book
     */
    
    public String getTitle() 
    {
        
        return title;   //2.74
    }
    
    /**
     * this method prints the title of the book to the terminal window
     */
    
    public void printTitle()  //2.75
    {
        System.out.println("the title of the book is " + title );
    }
    
    /**
     * this method prints the author of the book to the terminal
     */
    
    public void printAuthor()   //2.75
    {
        System.out.println(" the author of this book is " + author );
    }
    
    /**
     * this method returns the number of pages in the book
     */
    public int getPages()  //2.76
    {
    return pages;
}

    
    /**
     * this method changes the reference number 
     */
    public void setRefNumber(String refNumber){
       
        if(refNumber.length() != 3) {
       System.out.print(" you must enter 3 digits ");
            
       
    }else{
        reference = refNumber;  //2.80
       
    }
}
    
    /**
     * this method returns the reference number
     */
    
    public String getReference()
    {
    return reference;   //2.78
    
}

    /**
     * this method keeps track of how often the book has been borrowed
     */
    public int borrow()
    {
        borrowed = (borrowed + 1);
        return borrowed;  //2.81
    }
    
    
    /**
     * this method changes the reference number
     */

    /**
     * this method prints the details of the book, title, author and number of pages
     * and the reference number and the number of times the book has been borrowed
     */    

    public void printDetails()  //2.77, 2.79, 2.81
    {
        System.out.println(" the title of this book is " + title );  //2.77
        System.out.println(" the author of this book is " + author );  //2.77
        System.out.println(" the book has " + pages + " pages");  //2.77
        System.out.println(" the book has been borrowed " + borrowed + " times"); //2.81
        
        if (reference.length() > 2){
        System.out.println(" the reference number for the book is " + reference );
    }else{
        System.out.println(" zzz "); //2.79
    }}
    // Add the methods here ...
}