Task The task is to read a file, which consists of one date on each line. Each d
ID: 3889206 • Letter: T
Question
Task The task is to read a file, which consists of one date on each line. Each date should be stored in a Date object. If the next date is later than the previous date, a DateRange object should be created from the two dates. All the Date and DateRange objects should be printed out. Input and Output Consider the following input: June 17, 1997 July 23, 1997 September 28, 1980 September 31, 1980 Mar. 2, 1980 Apr 2, 1980 May 3, 1980 Nov 25, 1989 Dec 25, 1989 Jan 3, 1973 Note that the months might be written in different ways. Also, note that there is one invalid date. This data should result in the following output: Date: June 17, 1997 Date: July 23, 1997 DateRange: Date: June 17, 1997 Date: July 23, 1997 Date: September 28, 1980 Invalid Date Date: March 2, 1980 Date: April 2, 1980 DateRange: Date: March 2, 1980 Date: April 2, 1980 Date: May 3, 1980 DateRange: Date: April 2, 1980 Date: May 3, 1980 Date: November 25, 1989 DateRange: Date: May 3, 1980 Date: November 25, 1989 Date: December 25, 1989 DateRange: Date: November 25, 1989 Date: December 25, 1989 Date: January 3, 1973 Each of these lines should be the result of print statements like: System.out.printin(date) System.out.println (daterange) where date and daterange are Date and DateRange objects, respectively Reading in the Data Assume that the name of the file is dates.txt. In Eclipse, the file needs to be in the top directory of the project. Reading and printing all the dates and date ranges in the file should be accomplished by a sequence of code like: Scanner innull; try in Scanner (new File ("dates.txt.)); = new ) catch (FileNotFoundException exception System.err.println( "failed to open dates.txt) System.exit(l) while (in.hasNextLine)) String line in.nextLine) Date date new Date(line): System.out.println (date)Explanation / Answer
${temp}Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.