Advertisement
binibiningtinamoran

Book

Nov 16th, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. public class Book {
  2.     private int totalPages, totalChapters;
  3.     private double unitPrice;
  4.     private String title, author, ISBN;
  5.     protected String format = "Paper"; // need to take this value
  6.     private static final double DEFAULT_UNIT_PRICE = 15.00;
  7.  
  8.     public Book(String title, String author,
  9.             String ISBN, int totalPages, int totalChapters, double unitPrice) {
  10.         this.totalPages = totalPages;
  11.         this.totalChapters = totalChapters;
  12.         this.unitPrice = (unitPrice <= 0) ? DEFAULT_UNIT_PRICE : unitPrice;
  13.         this.title = title;
  14.         this.author = author;
  15.         this.ISBN = ISBN;
  16.     }
  17.  
  18.     public int getTotalPages() {
  19.         return totalPages;
  20.     }
  21.  
  22.     public void setTotalPages(int totalPages) {
  23.         this.totalPages = totalPages;
  24.     }
  25.  
  26.     public int getTotalChapters() {
  27.         return totalChapters;
  28.     }
  29.  
  30.     public void setTotalChapters(int totalChapters) {
  31.         this.totalChapters = totalChapters;
  32.     }
  33.  
  34.     public double getUnitPrice() {
  35.         return unitPrice;
  36.     }
  37.  
  38.     public void setUnitPrice(double unitPrice) {
  39.         this.unitPrice = unitPrice;
  40.     }
  41.  
  42.     public String getTitle() {
  43.         return title;
  44.     }
  45.  
  46.     public void setTitle(String title) {
  47.         this.title = title;
  48.     }
  49.  
  50.     public String getAuthor() {
  51.         return author;
  52.     }
  53.  
  54.     public void setAuthor(String author) {
  55.         this.author = author;
  56.     }
  57.  
  58.     public String getISBN() {
  59.         return ISBN;
  60.     }
  61.  
  62.     public void setISBN(String ISBN) {
  63.         this.ISBN = ISBN;
  64.     }
  65.  
  66.     public String getFormat() {
  67.         return format;
  68.     }
  69.  
  70.     @Override
  71.     public String toString() {
  72.         return "\nTitle: " + this.title +
  73.                 "\nAuthor: " + getAuthor() +
  74.                 "\nISBN: " + this.getISBN() +
  75.                 "\nNo. of Pages: " + totalPages +
  76.                 "\nNo. of Chapters: " + this.getTotalChapters() +
  77.                 "\nUnit Price: $" + unitPrice;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement