All pastes #44386 Raw Edit

Anonymous

public java v1 · immutable
#44386 ·published 2006-03-03 22:04 UTC
rendered paste body
import java.text.DecimalFormat;/** * This is a template class for Book.  * It defines a Book class used for the storage of Book Information *  *//** * @author Brent Garber * */public class Book {	//	instance variables	private String _title;	private double _price;	private int _quantity;		private DecimalFormat df1 = new DecimalFormat("##,###.00");	//	Default Constructor	/**	 * Constructs a default Book object	 */	public Book() {		this._title = "";		this._price = 0.00;		this._quantity = 0;			}	/**	 * Constructs a Book object with given instance attributes	 * @param title Title of the Book	 * @param price Price of the Book	 * @param quantity Number of Books in inventory	 */	public Book(String title, double price, int quantity) {		this._title = title;		this._price = price;		this._quantity = quantity;	}	/**	 * Sets the Book's Title	 * @param title	 */	public void setTitle(String title) {		this._title = title;	}		/**	 * Returns the title of the book	 * @return String Name of Book	 */	public String getTitle() {		return this._title;	}		/**	 * Sets the Book's Price	 * @param price	 */	public void setPrice(double price) {		this._price = price;	}		/**	 * Returns the Book's Price	 * @return double Price of Book	 */	public double getPrice() {		return this._price;	}		/**	 * Sets the number of this type of Book in the inventory	 * @param quantity	 */	public void setQuantity(int quantity) {		this._quantity = quantity;	}		/**	 * Returns the current inventory of the book	 * @return int Number of books in the inventory	 */	public int getQuantity() {		return this._quantity;	}		/**	 * Returns the Total Cost of the book	 * @param number Number of Books to Buy	 * @param taxRate Tax rate to apply to purchase	 * @return double Total Cost of the Books	 */	public double getTotalCost(int number, double taxRate) {		return number * (this.getPrice() * (1.0 + (taxRate / 100)) );	}		/**	 * Returns a rendering of the Book object	 * @return String version of object	 */	public String toString() {		return "The Book: " + super.toString() + " " + this.getTitle() + " $" + df1.format(this.getPrice()) + " " + this.getQuantity();	}}