Advertisement
anon_1294s

Book.java

Dec 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. public class Book {
  2.  
  3.     //Private Variables
  4.     private int isbn;
  5.     private String title;
  6.     private String author;
  7.     private double price;
  8.  
  9.     //GET isbn
  10.     public int getISBN(){
  11.         return this.isbn;
  12.     }
  13.  
  14.     //SET isbn
  15.     public void setISBN(int isbn){
  16.         this.isbn = isbn;
  17.     }
  18.  
  19.     //GET title
  20.     public String getTitle(){
  21.         return this.title;
  22.     }
  23.  
  24.     //SET title
  25.     public void setTitle(String title){
  26.         this.title = title;
  27.     }
  28.  
  29.     //GET author
  30.     public String getAuthor(){
  31.         return this.author;
  32.     }
  33.  
  34.     //SET author
  35.     public void setAuthor(String author){
  36.         this.author = author;
  37.     }
  38.  
  39.     //GET price
  40.     public double getPrice(){
  41.         return this.price;
  42.     }
  43.  
  44.     //SET price
  45.     public void setPrice(double price){
  46.         this.price = price;
  47.     }
  48.  
  49.     public Book() //default constructor Or parameterless constructor
  50.     {
  51.         this.isbn = 0000;
  52.         this.title = "Unknown";
  53.         this.author = "Unknown";
  54.         this.price = 0000;
  55.     }
  56.  
  57.  
  58.     public Book(int isbn, String title, String author, double price)
  59.     {
  60.         this.isbn=isbn;
  61.         this.title=title;
  62.         this.author = author;
  63.         this.price = price;
  64.     }
  65.  
  66.     public void displayBook()
  67.     {
  68.         System.out.println("\n\n\t\tISBN: " + this.isbn + "\n\t\tTitle: " + this.title + "\n\t\tAuthor: " + this.author + "\n\t\tPrice: " +this.price+"\n");
  69.     }
  70.  
  71.  
  72.     public String toString(){
  73.         return "\n\n\t\tISBN: " + this.isbn + "\n\t\tTitle: " + this.title + "\n\t\tAuthor: " + this.author + "\n\t\tPrice: " +this.price+"\n";
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement