Late-Fee Calculator

The following rules describe how one library charges for late fee.

  1. The basic rate is 5 bath per day.
  2. If the book is returned with in 2 days of its due date, no late fee will be charged. (On the 3rd day, the late fee will be 15 bath, for example.)
  3. No late fee will be charged for any days the library is closed. The library only closes on Sunday.

The skeleton for class LateFee and the declaration of our method under test calculate are as follow.

import java.util.Date;
public class LateFee {
	static int calculate(Date dueDate, Date currentDate) {
		return 0;
	}
}

Your task is to write a unit test LateFeeTest for method LateFee.calculate. Your unit test should include at least 5 interesting test cases for that method. You also have to implement the method that passes all these test cases.

Comments on date calculation

The code below is an example of how you create a Date object and calculate the day of week for that Date. Note that we use SimpleDateFormat.parse to create a Date object, and use GregorianCalendar to find day of week.

import java.text.*;
import java.util.*;
 
// ...
DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd");
try {
    Date dueDate = dfm.parse("2008-11-15");
    Calendar cal = new GregorianCalendar();
    cal.setTime(dueDate);
    System.out.println("" + cal.get(Calendar.DAY_OF_WEEK));
} catch (ParseException e) {}
software_testing/homework1/late_fee_calculator.txt · Last modified: 2008/11/15 18:13 by jittat
 
 
©2008 Another cool website by 80KV