Respuesta :
Answer:
Following is given the code as required with all necessary description as comments in it. The output is attached in last image.
Explanation:
I hope it will help you!
The program is an illustration of string manipulations.
String manipulations involve performing operations like merging and extracting strings.
The main() method of the program in Java, where comments are used to explain each line is as follows:
//This defines the main() method
public static void main(String[] args) {
//This creates a scanner object
Scanner input= new Scanner(System.in);
//This creates an array list
ArrayList<String>dates = new ArrayList<String>();
//This declares all variables as string
String date, month, day, year;
//The following loop is repeated for valid inputs
while (true) {
//This gets input for the date
date = input.nextLine();
//If input date is "-1"
if (date.equals("-1")) {
//This exits the loop
break;
}
//This adds all dates to the array list
dates.add(date);
}
//This iterates through the array list
for (int i = 0; i < dates.size(); i++) {
//The following try statement extracts the valid month, day and year from each date
try {
month = dates.get(i).substring(0, dates.get(i).indexOf(" "));
day = dates.get(i).substring(dates.get(i).indexOf(" ") + 1, dates.get(i).indexOf(","));
year = dates.get(i).substring(dates.get(i).indexOf(",") + 2, dates.get(i).length());
//This passes the month to the getMonthAsInt() method, and prints the date
System.out.println(getMonthAsInt(month) + "/" + day + "/" + year);
}
//This catches all invalid dates
catch (Exception e) {}
}
}
Read more about similar programs at:
https://brainly.com/question/23447959