编程语言

img yaohao803

10月10日

发表于2004/10/8 15:40:00  697人阅读

今天完成AnnualLease类的异常处理,同时完成了Boat和customer之间的关联,在Boat中加入了两个方法
1.public void assignBoatToCustomer(Customer aCustomer)  //船只和客户的关联
{
    setCustomer(Customer aCustomer);    //conect 1....1
    customer.setBoat(this);
}
2.public void assignBoatToSlip(aSlip)   //船只和船台的关联
 {
  setSlip(aSlip);
  slip.setBoat(this);
 }
另外增加了BOAT类的测试方法用来测试slip和 boat中各方法的实现:
3.public String tellAboutSelf()
 {
  //Boat information
  String boatDetails="I am a Boat"+
    "state reg number "+getStateRegistrationNo()+
    "length "+getLength()+
    "Manufacturer "+getManufacturer()+
    "Year "+getYear();
   String customerDetails="/n and Owner is "+
     customer.getName()+
     "Living in "+customer.getAddress()+
     "with Phone "+customer.getPhoneNo();
     return boatDetails+customerDetails; 
 }
//没有进行测试
整个Boat.java代码:
package com.tianyu.summer;
public class Boat
{
 private String stateRegistrationNo;
 private double length;
 private String manufacturer;
 private int year;
 private Customer customer;
 private Slip slip;
 public Boat(String aStateRegistrationNo,double aLength,String aManufacturer,int aYear,Customer aCustomer)
 {
  setStateRegistrationNo(aStateRegistrationNo);
  setLength(aLength);
  setManufacturer(aManufacturer);
  setYear(aYear);
  assignBoatToCustomer(aCustomer);
  setSlip(null);
 }
 public void assignBoatToCustomer(Customer aCustomer)
 {
  setCustomer(aCustomer);
  customer.setBoat(this);
 }
 public void assignBoatToSlip(Slip aSlip)
 {
  setSlip(aSlip);
  slip.setBoat(this);
 }
 public String tellAboutSelf()
 {
  //Boat information
  String boatDetails="I am a Boat"+
    "state reg number "+getStateRegistrationNo()+
    "length "+getLength()+
    "Manufacturer "+getManufacturer()+
    "Year "+getYear();
   String customerDetails="/n and Owner is "+
     customer.getName()+
     "Living in "+customer.getAddress()+
     "with Phone "+customer.getPhoneNo();
     return boatDetails+customerDetails;
   
 }
 public void setStateRegistrationNo(String aStateRegistrationNo)
 {stateRegistrationNo=aStateRegistrationNo;}
 public void setLength(double aLength)
 {length=aLength;}
 public void setManufacturer(String aManufacturer)
 {manufacturer=aManufacturer;}
 public void setYear(int aYear)
 {year=aYear;}
 public void setCustomer(Customer aCustomer)
 {customer=aCustomer;}
 public void setSlip(Slip aSlip)
 {slip=aSlip;}
 
 public String getStateRegistrationNo()
 {return stateRegistrationNo;}
 public double getLength()
 {return length;}
 public String getManufacturer()
 {return manufacturer;}
 public int getYear()
 {return year;}
 public Customer getCustomer()
 {return customer;}
 public Slip getSlip()
 {return slip;}
}

//完成lease的关联,原理和上面类相似,类的代码为:
package com.tianyu.summer;
import java.util.*;
public abstract class Lease
{
 private double amount;
 private Date startDate;
 private Date endDate;
 private Customer customer;
 private Slip slip;
 
 public Lease(Date aStartDate)
 {
  setStartDate(aStartDate);
  setEndDate(null);
  setAmount(0);
  setCustomer(null);
  setSlip(null);
 }
 public abstract double caculateFee(int aLength);
 
 public void setAmount(double anAmount)
 {amount=anAmount;}
 public void setStartDate(Date aStartDate)
 {startDate=aStartDate;}
 public void setEndDate(Date anEndDate)
 {endDate=anEndDate;}
 public void setCustomer(Customer aCustomer)
 {customer=aCustomer;}
 public void setSlip(Slip aSlip)
 {slip=aSlip;}
 
 public double getAmount()
 {return amount;}
 public Date getStartDate()
 {return startDate;}
 public Date getEndDate()
 {return endDate;}
 public Customer getCustomer()
 {return customer;}
 public Slip getSlip()
 {return slip;}
}
阅读全文
0 0

相关文章推荐

img
取 消
img