没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
JUnit 4.x in Eclipse, a Quick Tutorial
Wishnu Prasetya
November 28, 2008
This tutorial is for a bit more experienced Java programmers. I will assume:
• you know how to write JUnit tests (else see e.g. my JUnit 4.x Quick Tutorial).
• you are an Eclipse user; so you would know e.g. how to add a jar to your project’s build
path.
Setting up an example
Start a new project first; call it e.g. MyProject. Create in this project the following java class
(which should be called Subscription.java). This will be the class we are going to test.
public class Subscription {
private int price ; // subscription total price in euro-cent
private int length ; // length of subscription in months
/
**
*
A constructor to create a subsription.
*
/
public Subscription(int p, int n) {
price = p ;
length = n ;
}
/
**
*
Calculate the monthly subscription price in euro,
*
rounded up to the nearest cent.
*
/
public double pricePerMonth() {
if (length<=0 || price<=0) return 0 ;
double r = (double) price / (double) length ;
double fraction = Math.IEEEremainder(r,1.0) ;
if (fraction > 0)return Math.floor(r) + 1 ;
else return Math.floor(r) ;
}
/
**
*
Call this to cancel/nulify this subscription.
*
/
public void cancel() { length = 0 ; }
}
An instance of the above class represents a subscription to something (e.g. newspaper, but
it doesn’t really matter here). Each subscription has its total price, stored in the variable price.
This price is in Euro-cent. It also has the length of the subscription, given in months.
1
资源评论
- xiazai5824822432013-04-25不错要是中文版就更好啊
yangfujun011
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功