The following rules describe how one library charges for late fee.
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.
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) {}