Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Book {
- // private instance variable, not accessible from outside this class
- private String Name;
- private String Author;
- private double Price;
- private int qtyInStock;
- // Constructors for a new instance of
- public Book (String Name, String Author, double Price) {
- this.Name = Name;
- this.Author = Author;
- this.Price = Price;
- }
- public Book (String Name, String Author, double Price, int qtyInStock) {
- this.Name = Name;
- this.Author = Author;
- this.Price = Price;
- this.qtyInStock = qtyInStock;
- }
- // A public method for retrieving the Name, Author, Price and QtyInStock
- public String getName() {
- return Name;
- }
- public String getAuthor() {
- return Author;
- }
- public double getPrice() {
- return Price;
- }
- public int getQtyInStock() {
- return qtyInStock;
- }
- // Setter for instance variable Price and qtyInStock
- public void setPrice(int Price) {
- this.Price = Price;
- }
- public void setQtyInStock(int qtyInStock) {
- this.qtyInStock = qtyInStock;
- }
- // toString method
- public String toString() {
- return Name + " by " + Author.toString();
- }
- //toString() that returns "'book-name' by author-name (gender) at email".
- //(Take note that the Author's toString() method returns "author-name (gender) at email".)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement