/* CIS 3270 Fall 2006 Assignment 5 Solution * By Jack G. Zheng * September 25, 2006 * */ package zheng.cis3270.assignment; import java.text.*; public class Book { private String bookTitle; private double listPrice; private EditorialReview review; public Book(String title, double price, EditorialReview review) { this.setBookTitle(title); this.setReview(review); this.setListPrice(price); } private double getDiscountPrice() { double discount=0; switch (review.getRating()) { case 5: discount=0;break; case 4: discount=0.05;break; case 3: discount=0.1;break; case 2: discount=0.15;break; case 1: discount=0.2;break; } return this.listPrice*(1-discount); } public void printBookInfo() { System.out.println("Book Title:\t" + this.getBookTitle()); DecimalFormat df=new DecimalFormat("$#,###.00"); System.out.println("List Price:\t" + df.format(this.getListPrice())); System.out.println("Discount Price:\t" + df.format(this.getDiscountPrice())); System.out.println("Editorial Review:"); review.printReview(); } public static void main(String[] args) { EditorialReview r1=new EditorialReview( "Good book!","Publisher Weekly",4); Book book = new Book("Weaving the Web", 14.99, r1); book.printBookInfo(); } public String getBookTitle() { return bookTitle; } public void setBookTitle(String bookTitle) { this.bookTitle = bookTitle; } public double getListPrice() { return listPrice; } public void setListPrice(double listPrice) { this.listPrice = listPrice; } public EditorialReview getReview() { return review; } public void setReview(EditorialReview review) { this.review = review; } } class EditorialReview { private String content; private String reviewer; private int rating; public EditorialReview(String content, String reviewer, int rating) { this.content=content; this.reviewer=reviewer; this.rating=rating; } public int getRating() { return rating; } public void printReview() { System.out.println("From "+reviewer+" (rating: "+rating+")"); System.out.println(content); } }