2008-12-13 19:51
coonrx8
import java.util.Scanner;
class Book{
private String name;
private String author;
private String publisher;
private int price;
Book(){
}
Book(String name, String author, String publisher, int price){
this.name = name;
this.author = author;
this.publisher = publisher;
this.price = price;
}
public String toString(){
return "®Ñ¦W¡G" + this.name + "\n§@ªÌ¡G" + this.author +
"\n¥Xª©ªÀ¡G" + this.publisher + "\nq»ù¡G" + this.price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public double getSellPrice(){
Calculator calculator = new Calculator();
double price = (double)this.price;
return calculator.calculate(price, 0.8);
}
}
class ComBook extends Book{
boolean hasDisc;
String hasDisc(){
return this.hasDisc==true?"ªþ¥úºÐ":"¨S¥úºÐ";
}
void setHasDisc(boolean hasDisc){
this.hasDisc = hasDisc;
}
ComBook(){
}
ComBook(String name, String author, String publisher,
int price, boolean hasDisc){
super( name, author, publisher, price);
this.hasDisc = hasDisc;
}
}
class Comic extends Book{
boolean isComic;
String isComic(){
return this.isComic==true?"®Ñ":"º©µe®Ñ";
}
void setHasDisc(boolean isComic){
this.isComic = isComic;
}
class BookShop{
private ComBook[] comBook = new ComBook[6];
BookShop(){
comBook[0] = new ComBook("¸ê®Æµ²ºc\t","´¿§Ó°a\t","ùÖ®p¤å¤Æ\t",500,true);
comBook[1] = new ComBook("J2EE\t\t\t","·¨®õª@\t","³ÕºÓ¤å¤Æ\t",380,true);
comBook[2] = new Comic("¤õ¼v§ÔªÌ\t","©¤¥»»ô¥v\t","ªF¥ß",80,true);
comBook[3] = new ComBook("MacOSX 10.5\t\t","¬I«Â»Ê¬ã¨s«Ç","ºX¼Ð\t",560,true);
comBook[4] = new Comic("ÄéÄx°ª¤â\t","¤«¤W¶¯«Û\t","ªF¥ß",80,true);
comBook[5] = new ComBook("Javaµ{¦¡³]pÃÀ³N\t","Deitel\t","¥þµØ¹Ï®Ñ\t",650,true);
}
public String toString(){
String result = "";
for(int i=0;i<comBook.length;i++){
result += "("+(i+1)+")"+comBook[i].getName()+(comBook[i].getName().length()>5?"\t":"\t\t");
result += comBook[i].getAuthor()+"\t";
result += comBook[i].getPublisher()+"\t";
result += comBook[i].getPrice()+"\t";
if(comBook[i] instanceof ComBook){
result += ((ComBook)comBook[i]).hasDisc()+"\t";
}else{
result += ((isComic)comBook[i]).isComic()+"\t";
result += comBook[i].getSellPrice()+"\n";
}
return result;
}
void Execute(){
int item=0, sum=0;
double amount = 0, comCount=0, comicCount=0;
Calculator calculator = new Calculator();
Scanner sc = new Scanner(System.in);
System.out.print("½Ð¿é¤JÁʶR®Ñ¥»ªº½s¸¹(1~6¡A-1¥Nªíµ²§ô)¡G");
item = sc.nextInt();
if(item>0){
sum += comBook[item-1].getPrice();
}
while(item!=-1);
System.out.print("§A¤@¦@¶R¤F"+comBook+"¥»¹q¸£®Ñ»P"+ iscomic +"º©µe®Ñ¡A¦@"+ sum +"¤¸¡A");
}
}
class Calculator{
double calculate(double number, double discount){
return number * discount;
}
}
public class Work_1 {
/**
* @param args
*/
public static void main(String[] args) {
BookShop bookShop = new BookShop();
System.out.println(bookShop);
bookShop.Execute();
}
}}