// Convert user-specified date from American to standard // format import java.util.*; class DateTranslation { // main(): application entry point static public void main(String args[]) { // produce a legend (Step 1) System.out.println("Date format translator"); System.out.println(" Converts a date from an American" + " format (e.g., July 4, 1776)"); System.out.println(" to standard format (e.g.," + " 1776-July-4)."); System.out.println(); // prompt the user for a date in American format (Step 2) System.out.print("Enter a date in American format: "); // acquire the input entered by the user (Step 3) Scanner stdin = new Scanner(System.in); String buffer1 = stdin.nextLine(); // echo the input back (Step 4) System.out.println("The translation of"); System.out.println(" " + buffer1); // get month entered by the user (Step 5) String buffer2 = buffer1.trim(); int m = buffer2.indexOf(" "); String month = buffer2.substring(0, m); String buffer3 = buffer2.substring(m + 1); // get day entered by the user (Step 6) String buffer4 = buffer3.trim(); int n = buffer4.indexOf(","); String day = buffer4.substring(0, n); String buffer5 = buffer4.substring(n + 1); // get year entered by the user (Step 7) String year = buffer5.trim(); // create standard format version of input (Step 8) String standardDate = year + "-" + month + "-" + day; // display the translation (Step 9) System.out.println("to standard format is"); System.out.println(" " + standardDate); } }