2011-3-15 01:15 ²]À㪺¤p²Â²Â
À°§Ú¸Ñ¨M°ÝÃD

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 + "\n­q»ù¡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;i5?"\t":"\t\t");
      result += combook[b].getauthor()+"\t";
      result += combook[b].getpublisher()+"\t";
      result += combook[b].getprice()+"\t";
      if(combook[b] instanceof combook){
      result += ((combook)combook[b]).hasdisc()+"\t";
      }else{
      result += ((iscomic)combook[b]).iscomic()+"\t";
      result += combook[b].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();
  }

}}

­¶: [1]
¬d¬Ý§¹¾ãª©¥»: À°§Ú¸Ñ¨M°ÝÃD


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.