软件构造课程实验4

实验四:

Debugging, Exception Handling, and Defensive Programming

1.实验指导:

在这里插入图片描述

2.Error and Exception Handling:

我定义的需要处理的异常,包括:
在这里插入图片描述

异常类异常情况
IllegalLabelException某个元素定义的标签非法,输入文件中存在不能识别的标签名时抛出
IllegalRelationException文件中各元素之间的依赖关系不正确,如未添加物体就添加相应关系
IllegalNumberofComponentsException元素定义中分量的数目与规范不符合时抛出
SameLabelException存在标签一样的元素时抛出
IllegalAngleException初始角度不在在[0,360)之间时抛出
IllegalTurnaroundException公转方向不符合规范时抛出
IllegalNameException元素名称不符合规范时抛出,如定义原子名称为rb
NumberformatException数字组成不符合规范时抛出,如亲密度大于1,或出现四位小数
SameTrackradiusException存在两个行星的轨道半径相同时抛出
StringformatException元素定义中分量的字符串与规范不符合时抛出

3.Assertion保障pre-/post-condition:

3.1.ConcreteCircularOrbit:

// defense strategy:
// TrackSystem!=null
// relations!=null
// addtrack(double radius): radius>0
// subtrack(double radius): radius>0
// addCentralObject(L centralObject): centralObject!=null
// addPhysicalObject(E physicalObject,double radius): physicalObject!=null radius>0
// subPhysicalObject(String name,double radius): radius>0
// addrelation(String r1,String r2,double weight): 0<weight<=1
// transit(E object,double radius): radius>0

3.2.StellarSystem:

// defense strategy:
// readFromFile(File corpus): corpus!=null

3.3.AtomStructrue:

// defense strategy:
// transit(double source,double target): source>0,target>0
// readFromFile(File corpus): corpus!=null

3.4.SocialNetworkCircle:

// defense strategy:
// getdistance(Friend f):f!=null
// readFromFile(File corpus): corpus!=null
// addrelation(String f1,String f2,double weight):0<weight<=1

4.实验报告:

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值