10月10日

今天完成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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值