How to develop a class MonthDate to print out the following output ? I know one of the method is to use toString, but how?
Code:
import java.util.Arrays;
public class SortMonthDate {
public static void main(String[] args) {
MonthDate[] mdates = new MonthDate[5];
mdates[0] = new MonthDate(22, 7);
mdates[1] = new MonthDate(25, 8);
mdates[2] = new MonthDate(25, 6);
mdates[3] = new MonthDate(28, 9);
mdates[4] = new MonthDate(5, 9);
print(mdates);
Arrays.sort(mdates);
print(mdates);
}
static <T> void print(T[] a) { // generic method
for (T t : a) {
System.out.printf("%s ", t);
}
System.out.println();
}
}
Expected Output:
22/7 25/8 25/6 28/9 5/9
28/9 5/9 25/8 22/7 25/6