package project3; import java.text.*; public abstract class Book implements Comparable { private String author; private String title; private int pages; private int copiesSold; private double price; private DecimalFormat format; public Book(String title, String author, int pages, double price) { this.author = author; this.title = title; this.pages = pages; this.price = price; copiesSold = 0; format = new DecimalFormat("###,###,###,###.00"); } public abstract String getType(); public String getAuthor() { return author; } public String getTitle() { return title; } public int getPages() { return pages; } public int getCopiesSold() { return copiesSold; } public double getPrice() { return price; } public void incrementCopiesSold(int n) { if (n > 0) copiesSold += n; } public String getShortDescription() { return title + " by " + author + " sales: "+grossSalesString(); } private String grossSalesString() { return "$ "+format.format(price*copiesSold); } public String getLongDescription() { return "title: " + title + "\n" + "author: " + author + "\n" + "pages: " + pages + "\n" + "price: $" + format.format(price) + "\n" + "sold: " + copiesSold + "\n" + "gross: "+ grossSalesString() + "\n" + "type: " + getType() + "\n"; } public int compareTo(Object obj) { Book otherBook = (Book)obj; return title.compareTo(otherBook.title); } public boolean equals(Book otherBook) { return title.equals(otherBook.title); } }