Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 24th, 2012  |  syntax: Java  |  size: 2.33 KB  |  hits: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Book
  2. {
  3.     private String author;
  4.     private String title;
  5.     public int pages;
  6.     public String refNumber;
  7.     int borrowed;
  8.     boolean courseText;
  9.  
  10.     public Book (String bookAuthor, String bookTitle, int bookPages, boolean newCourseText)
  11.     {
  12.         author = bookAuthor;
  13.         title = bookTitle;
  14.         pages = bookPages;
  15.         refNumber = "";
  16.         courseText = newCourseText;
  17.     }
  18.  
  19.     public String getAuthor ( ) {
  20.         return author;
  21.     }
  22.  
  23.     public String getTitle ( ) {
  24.         return title;
  25.     }
  26.  
  27.     public int getPages ( ) {
  28.         return pages;
  29.     }
  30.    
  31.     public String refNumber ( ) {
  32.         return refNumber;
  33.     }
  34.    
  35.     public void setRefNumber(String ref) {
  36.         if (ref.length() >= 3)
  37.         {
  38.             refNumber = ref;
  39.         }
  40.         else
  41.         {
  42.             System.out.println("##################################################");
  43.             System.out.println("Reference number cannot be less than 3 characters!");
  44.             System.out.println("##################################################");
  45.         }
  46.     }
  47.    
  48.     public String getRefNumber ( ) {
  49.         return refNumber;
  50.     }
  51.    
  52.     public void increaseborrow() {
  53.         borrowed = borrowed + 1;
  54.     }
  55.    
  56.     public int getBorrowed() {
  57.         return borrowed;
  58.     }
  59.    
  60.     public boolean isCourseText() {
  61.         return courseText;
  62.     }
  63.  
  64.     public void printBook()
  65.     {
  66.         System.out.println("***********************************");
  67.         System.out.println("Author: " + author + ".");
  68.         System.out.println("Title: " + title + ".");
  69.         System.out.println("Pages: " + pages + ".");
  70.         if (refNumber.length() >= 3) {
  71.         System.out.println("Ref No.: " + refNumber + ".");
  72.     }   else {
  73.         System.out.println("No reference number!");
  74.     }
  75.         if (borrowed == 0) {
  76.         System.out.println(title + " hasn't been borrowed yet.");
  77.     }
  78.         else if (borrowed == 1)
  79.         {
  80.         System.out.println(title + " has been borrowed " + borrowed + " time.");
  81.     }
  82.         else {
  83.         System.out.println(title + " has been borrowed " + borrowed + " times.");
  84.     }
  85.         System.out.println("Text book on a course: " + courseText + ".");
  86.         System.out.println("***********************************");
  87.     }
  88. }