RioSurya12

Untitled

Sep 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 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 (Insert your name here.)
  7. * @version (Insert today’s date here.)
  8. */
  9.  
  10. import java.util.Scanner;
  11.  
  12. public class Book
  13. {    
  14.     Scanner scan = new Scaner(System.in)
  15.     // The fields.    
  16.     private String author;    
  17.     private String title;
  18.     private int pages;
  19.     private String refNumber;
  20.     private int borrowed;
  21.    
  22.    
  23.     /**    
  24.         * Set the author and title fields when this object    
  25.         * is constructed.    
  26.         */    
  27.         public Book(String bookAuthor, String bookTitle, int bookPages)    
  28.         {        
  29.             author = bookAuthor;        
  30.             title = bookTitle;
  31.             pages = bookPages;
  32.             refNumber = "";
  33.             borrowed = 0 ;
  34.                
  35.         }
  36.        
  37.         public String getAuthor
  38.         {
  39.             return author;
  40.         }
  41.  
  42.         public String getTitle
  43.         {
  44.             return title;
  45.         }
  46.  
  47.         public String getRefNumber()   
  48.         {
  49.             return refNumber;
  50.         }
  51.  
  52.         public void printAuthor()
  53.         {
  54.             System.out.println("Author: " + author);   
  55.         }
  56.        
  57.         public void printTitle()
  58.         {
  59.             System.out.println("Title: " + title);
  60.         }
  61.        
  62.         public int getPages()
  63.         {
  64.             return pages;
  65.         }
  66.  
  67.         public int getBorrowed()
  68.         {
  69.             return borrowed;
  70.         }
  71.        
  72.         public void setRefNUmber(String ref)
  73.         {
  74.             if(ref.length() >= 3)
  75.             {
  76.                 refNumber = ref;
  77.             }
  78.            
  79.             else
  80.             {
  81.                 System.out.println("Error bro! at least 3 character");
  82.             }
  83.         }
  84.  
  85.         public void borrow()
  86.         {
  87.             borrowed = borrowed + 1;
  88.         }
  89.         public void printDetails()
  90.         {
  91.             System.out.println("Title: " + title + ", ");
  92.             System.out.println("Author: " + author + ", ");
  93.             System.out.println("Pages: " + pages);
  94.  
  95.             if (refNUmber.length() != 0)
  96.                 {
  97.                     System.out.println("Ref. Num   :" + refNumber);
  98.                 }
  99.                
  100.             else
  101.                 System.out.println("Ref. Num  : ZZZ");
  102.         }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment