Calculate date for ordinal day of week in month I am writing some date utility methods for a project.
One of the methods will answer the following questions (for example):

'When is the (3rd) (Monday) of (February) in the year (2018)'
'When is the (1st) (Wednesday) of (October) in the year (2020)'


The method accepts the 4 int value parameters as arguments, and will return a Date.

Here is the method as written:

/**
 * Example usage:
 * find the 3rd Monday of February, in the year 2018 getDayOfMonth(3, Calendar.MONDAY, Calendar.FEBRUARY, 2018)
 * find the 1st Tuesday of October, in the year 2017 getDayOfMOnth(1, Calendar.TUESDAY, Calendar.OCTOBER, 2017)
 * @param n occurrence count
 * @param dayOfWeek day of week to find
 * @param month month to use
 * @param year year to use
 * @return Date that the nth dayOfWeek occurs
 */
public static Date getDate(int n, int dayOfWeek, int month, int year){
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    int matchCount = 0;

    while(true){
        if(calendar.get(Calendar.DAY_OF_WEEK) == dayOfWeek) {
            matchCount++;
        }
        if(matchCount == n){
            break;
        }
        calendar.add(Calendar.DATE, 1);
        if(calendar.get(Calendar.MONTH) != month){
            break;
        }
    }

    if(matchCount != n){
        throw new RuntimeException("error");
    }

    return calendar.getTime();
}


I am struggling to come up with a good name for the method and the 1st parameter.
For the parameter, may I suggest nthOccurrence? Alternatively, anything that communicates what exactly it means should be alright, given that it's at a pretty contained location - even nthTimeDayOfWeekOccursInMonth wouldn't be terrible, especially since dayOfWeek and month are also parameters.

The method is harder, mainly because the thing you're calculating doesn't have a great name. "Return the nth occurrence of a weekday in a given month of a given year" doesn't lend itself to brevity. I would take one of two routes:

Does the assignment / class / professor have a term for this functionality? "Weekday oracle" or something equally obscure works perfectly if it's the way that everyone else who will see this code knows to refer to this thing.

If not, I would name it what it is; something like getDateOfNthTimeDayOfWeekOccursInMonth - this would pair well with naming that first parameter nthOccurrence. In this case, I think information (what exactly can I expect this to do) trumps brevity, because what it does is not very common / intuitive.