/* LCS Week 6 * 10/8/06 * A Book in the book store. * Input : purchase and sales of books * Output : inventory of current books and total profit */ /** * Represents an individual title on the shelves */ public class Book { private String title; private double price; private String author; private int numberSold; private int copiesOnHand; private double grossProfit; /** * create new book object * * @param aTitle - this books title * @param aAuthor - the books author * @param aPrice - this books initial price */ public Book(String aTitle, String aAuthor, double aPrice) { title = aTitle; price = aPrice; author = aAuthor; numberSold = 0; copiesOnHand = 0; } /** * sell a single copy of the book * @return true iff there was a copy of sell */ public void sellCopy() { ... } /** * stock a shipment of this book * * @param quantity - the number of copies of this book stocked */ public void getShipment(int quantity) { copiesOnHand += quantity; } /** * reduce the price of this book * * @param by - the amount to reduce the price by */ public void lowerPrice(double by) { if (by > 0) { price -= by; } else { // FIX ME oops ... need to raise some kind of exception! } } /** * for the inventory return the title, author, number on hand and gross sales * * @return - inventory line for the book */ public String toString() { return title + " " + author + " copies left " + copiesOnHand + " gross sales " + grossProfit; } public static void main (String [] args) { Book catInTheHat = new Book("Cat in the Hat", "Dr. Seuse", 5.99); System.out.println("cat book = " + catInTheHat); catInTheHat.getShipment(10); catInTheHat.sellCopy(); System.out.println("cat book = " + catInTheHat); catInTheHat.sellCopy(); System.out.println("cat book = " + catInTheHat); catInTheHat.lowerPrice(1.00); catInTheHat.sellCopy(); System.out.println("cat book = " + catInTheHat); // 1: prompt user for choice // 2: if choice == 1 quit // 3: if choice == 2 sell a copy // 4: if choice == 3 stock a shipment // 5: print current 'inventory' // 6: goto 1 } }