I need to ask the user for 3 dates (mm/dd/yyyy) and then it needs to print the earliest, latest and the average year. I am TERRIBLE at this & am taking the class because I have to. I don't know how to compare dates any other way than how you would compare numbers (<,>,==). Please help me fix this.
import java.util.*;
public class proj6 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter 3 dates: ");
String list = s.nextLine();
StringTokenizer st = new StringTokenizer(list, ", ");
String[] dates = new String[st.countTokens()];
for (int i = 0; i < dates.length; i++) {
dates[i] = st.nextToken();
}
proj6.printEarliest(dates);
int[] arr= new int[0];
proj6.printLatest(dates);
int[] arr2= new int[0];
proj6.printAvgYear(dates);
int[] arr3= new int[0];
}
public static int getMonth(String date) {
StringTokenizer st = new StringTokenizer(date, "/");
return Integer.parseInt(st.nextToken());
}
public static int getDay(String date) {
StringTokenizer st = new StringTokenizer(date, "/");
st.nextToken();
return Integer.parseInt(st.nextToken());
}
public static int getYear(String date) {
StringTokenizer st = new StringTokenizer(date, "/");
st.nextToken();
st.nextToken();
return Integer.parseInt(st.nextToken());
}
public static void printEarliest(String[] dates) {
Scanner s= new Scanner(System.in);
int getMonth;
int getDay;
int getYear;
int currentDay=getDay(dates[0]);
int currentMonth=getMonth(dates[0]);
int currentYear=getYear(dates[0]);
System.out.print(getMonth(dates[0])+"/"+getDay(dates[0])+"/"+getYear(dates[0]));
int indexearliest = 0;
for(int i = 0; i < dates.length; i++)
{
if (dates[indexearliest] <= (dates[i]));
{
indexearliest = i;
}
}
System.out.println("Earliest date: "+i);
}
public static void printLatest(String[] dates) {
Scanner s= new Scanner(System.in);
int getMonth;
int getDay;
int getYear;
int currentDay=getDay(dates[0]);
int currentMonth=getMonth(dates[0]);
int currentYear=getYear(dates[0]);
System.out.print(getMonth(dates[0]) + "/"+ getDay(dates[0]) + "/"+ getYear(dates[0]));
int indexlatest = 0;
for(int i = 0; i < dates.length; i++)
{
if (dates[indexlatest]<= compareTo(dates[i]));
{
indexlatest = i;
}
}
System.out.println("Latest date: "+ i);
}
public static void printAvgYear(String[] dates) {
Scanner s= new Scanner(System.in);
int getYear;
int currentYear=getYear(dates[0]);
System.out.print(getYear(dates[0]));
int indexyear = 0;
for(int i = 0; i < dates.length; i++)
{
if(dates[indexyear]=dates[i])
{
indexyear=indexyear/3;
indexyear = i;
}
}
System.out.println("Average year: "+i);
}
}