⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 purchaser.java

📁 构建网上购书最优联盟 此篇文章重在构建囊括最多变量因素的网上购书联盟。计算最优则变成了不断测试不断更改变量的统计型问题。而联盟要求的最低构建要素是: &#61548 联盟中心到站点的运输费
💻 JAVA
字号:
package tomato;



abstract class Purchaser {
  
  private Location d_location;
  protected int d_requirement;
  protected Book d_book;
  protected double d_totalCharge_recently;
  protected double d_totalCharge_byself;
  protected double d_totalCharge_privousfinal;
  
  protected static Bookstore d_bookstore;	
  protected static int d_numBS = 0;
  
  public Purchaser(Location location,Book book,int requirement){ 
   
    d_requirement = requirement;
    d_location = location;
    d_book = book;	
    d_totalCharge_recently = 0;
    d_totalCharge_privousfinal = 0;
    d_totalCharge_byself = 0;
  }
  /*
   private void Purchaser(Purchaser purchaser);{ 
   
    d_requirement = purchaser.d_requirement;
    d_location.SetLocation(purchaser.d_location);
    d_book = purchaser.d_book;
    d_totalCharge_recently = purchaser.d_totalCharge_recently;	
  }*/
  
  //访问
  public Location GetLocation(){
  
     return d_location;	
  }
  
  public int GetRequirement(){
  
     return d_requirement;
     
  }
  
  public Book GetBook(){
  
     return d_book;
     
  }
  
  
  //显示
  //The method should be used after method CalculateCharge()
  public void Display( ){  
       
     System.out.println("The Purchaser's requirement is   "+this.GetRequirement());
     System.out.println("The Purchaser's payment is       "+this.GetPayment());
     System.out.println("The Purchaser's pre_final pay is "+d_totalCharge_privousfinal);
     System.out.println("The Purchaser's final pay is     "+d_totalCharge_recently);
     this.d_location.Display();
     System.out.println();

     
  }
  
  //计算
  public void CalculateCharge(Bookstore bookstore,double perKmFreight){
       
     d_totalCharge_byself = this.GetPayment() +  GetLocation().CalculateDistance(bookstore.GetLocation()) * GetRequirement()* perKmFreight;
     d_totalCharge_recently = d_totalCharge_byself;
  }
  
  public double GetPayment( ){
    
    return GetRequirement() * GetBook().GetPrice(this);	
  }
  
  public boolean JoinAlliance(Alliance alliance){
    
    if ( d_totalCharge_recently >= (alliance.FreightbySinglePerson(this)+alliance.PaymentbySinglePerson(this)) ){
        
        d_totalCharge_privousfinal = d_totalCharge_recently;
        d_totalCharge_recently = (alliance.FreightbySinglePerson(this)+alliance.PaymentbySinglePerson(this));
        return true;
    }    
    else	
       
        return false;
            	
  }
  
  //设置环境
  public static void SetBookstore(){
    
    BookstoreManifest BSManifest = new BookstoreManifest();
    BookstoreManifest.Display();
    System.out.println();
    System.out.print("1.Please Inupt the bookstore number where you want to purchase: ");
    d_numBS = SavitchIn.readInt()-1;
    
    d_bookstore = BookstoreManifest.SelectBookstore(d_numBS);
    
    System.out.println("The bookstore you choosed is:"+d_bookstore.GetBookstorename());
    System.out.println();
    
  }
  
  public static int SettargetBook(){
    
    d_bookstore.Display();
    System.out.println();
    int d_num = 0;
    
    boolean flag0 = false;
    while (!flag0){
       
       System.out.print("2.Please Inupt the book number which you want to purchase: ");
       d_num = SavitchIn.readInt() - 1;
       System.out.println();

       System.out.println("The book which you want to purchase is: ");
       d_bookstore.SelectBook(d_num).Display();
       System.out.println();

       System.out.print("Are you sure your want? (Y/N) ");
       char sure = SavitchIn.readChar();
       
       if ( sure == 'N')
          flag0 = false;
       else
          flag0 = true;    
    }
    
    return d_num;
    	
  }
  
  public static int Setmaxper(){
    
      System.out.print("3.Please Inupt the max purchase number by singleperson: ");
      int d_maxper = SavitchIn.readInt();
      System.out.println("The max purchase number by singleperson: "+d_maxper);
      System.out.println();
      
      return d_maxper;
    
  }
  
  /*
  public static void main(String[]args){
  	
    SetBookstore();
     
    Location location = new Location(23,14);	
    Purchaser aTest = new Purchaser(location,d_bookstore.SelectBook(SettargetBook()),Setmaxper());	

    aTest.CalculateCharge(d_bookstore,SetperKmFreight());
    aTest.Display();   
    
 }
  */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -