Advertisement
Guest User

Book

a guest
Apr 16th, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. public class Book {
  2.     // private instance variable, not accessible from outside this class
  3.         private String Name;
  4.         private String Author;
  5.         private double Price;
  6.         private int qtyInStock;
  7.        
  8.     // Constructors for a new instance of
  9.         public Book (String Name, String Author, double Price) {
  10.             this.Name = Name;
  11.             this.Author = Author;
  12.             this.Price = Price;
  13.         }
  14.        
  15.         public Book (String Name, String Author, double Price, int qtyInStock) {
  16.             this.Name = Name;
  17.             this.Author = Author;
  18.             this.Price = Price;
  19.             this.qtyInStock = qtyInStock;
  20.         }
  21.        
  22.     // A public method for retrieving the Name, Author, Price and QtyInStock
  23.         public String getName() {
  24.             return Name;
  25.         }
  26.            
  27.         public String getAuthor() {
  28.             return Author;
  29.         }
  30.        
  31.         public double getPrice() {
  32.             return Price;
  33.         }
  34.        
  35.         public int getQtyInStock() {
  36.             return qtyInStock;
  37.         }
  38.        
  39.     // Setter for instance variable Price and qtyInStock
  40.         public void setPrice(int Price) {
  41.             this.Price = Price;
  42.         }
  43.        
  44.         public void setQtyInStock(int qtyInStock) {
  45.             this.qtyInStock = qtyInStock;
  46.         }
  47.        
  48.     // toString method
  49.         public String toString() {
  50.                return Name + " by " + Author.toString();
  51.         }
  52.  
  53.         //toString() that returns "'book-name' by author-name (gender) at email".
  54.         //(Take note that the Author's toString() method returns "author-name (gender) at email".)
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement