Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create a Java project in Maven.
- Read from an input file called "input.txt." I have supplied one test file, but I may run it against other files that meet the specification. I suggest that you make a few very short files with just two or three lines of data so that you can check your work.
- The file input.txt contains lines of data. In the sample file provided, The lines have the following characteristics
- Lines are "colon delimited"
- Valid lines contain two fields. (Invalid lines should be ignored when processing)
- The number of lines is unknown in advance
- Dates are in "standard" US format of month/day/year
- If there are exactly two dates on a line, those dates may be assumed to be valid dates.
- For each line of text in the file:
- Split the line of text on the tab.
- If there are exactly two fields on the line, process the line. Ignore lines with other than two fields.
- Use a method to split the date into the month, day, and year fields. The method should return an instance of the LocalDate class.
- Use a method to print the dates in order. They should be printed on the same line with a \t character between. If the dates match exactly, then the order does not matter. The earlier date should be printed first, and the later date printed last.
- At the end of the program print the number of date-pairs processed.
- Text for an input.txt file is provided at the end of this assignment. You may test against this file, but I suggest that you also test against other data. You may want to make a file with only a handful of lines of data to help you check your results.
- Pseudocode
- main()
- Scanner input = openFile("input.txt)
- int pairsProcessed
- pairsProcessed = processDates(input)
- close input
- print pairsProcessed
- processDates(Scanner input)
- int n = 0;
- while input has more lines
- line = input.nextLine()
- String[] dates = line.split(":");
- if (dates.length == 2)
- n++
- LocalDate a = makeDate(dates[0]);
- LocalDate b = makeDate(dates[1]);
- if( a is before b) Note that (a < b) will not work!
- print a b
- else
- print b a
- return n;
- makeDates(String s)
- Localdate date = null;
- String[] parts = split s on the "/" character
- int month = Integer.parseInt(parts[0])
- int day = ...
- int year=...
- date = LocalDate.of( ... )
- return date
- Sample test data
- 4/10/2017:3/10/2018
- 4/2/2011:2/29/2004
- 12/29/2011:12/29/2011
- 4/20/2011:11/13/2010
- 2/12/2019:2/26/2020
- 10/24/2018:11/29/2019
- 5/27/2013:11/22/2012
- 11/1/2010:11/2/2011
- 1/19/2020:8/7/2019
- 7/12/2011:6/20/2012
- 12/14/2013:6/12/2013
- 3/1/2013:8/10/2012
- 8/26/2017:8/9/2018
- 1/18/2014:1/11/2015
- 7/4/2014:7/10/2015
- 7/1/2017:6/17/2018
- 2/15/2021:2/1/2022
- 3/1/2014:4/3/2015
- 10/28/2010:11/24/2011
- 10/12/2022:4/17/2022
- 4/12/2014:4/13/2015
- 11/17/2012:5/22/2012
- 1/15/2020:7/23/2019
- 4/4/2017:9/25/2016
- 3/1/2017:3/13/2018
- 7/17/2013:8/1/2014:4/4/2017:9/25/2016
- 12/25/2010:12/17/2011
- 7/25/2012
- 12/14/2017:12/3/2018
- 8/27/2015:3/6/2015
- 7/16/2008:12/21/2007
- 4/20/2017:4/14/2018
- 4/6/2017:3/13/2018
- 12/3/2013:11/15/2014
- 2/28/2018:3/28/2019
- 9/17/2020:9/29/2021
- 3/4/2009:3/4/2010
- 2/10/2014:2/11/2015
- 5/6/2013:11/4/2012
- 5/1/2009:10/31/2008
- 9/8/2020:2/29/2020
- 8/25/2014:9/6/2015
- 11/23/2011:5/3/2011
- 6/17/2015:12/24/2014
- 4/15/2017:10/9/2016
- 5/18/2016:4/12/2017
- 2/27/2013:9/11/2012
- 2/4/2027:1/20/2028
- 11/11/2019:5/3/2019
- 4/6/2016:10/7/2015
- 1/25/2016:7/27/2015
- 10/14/2012:4/29/2012
- 3/12/2011:2/27/2012
- 11/22/2012:11/1/2013
- 6/15/2014:5/22/2015
- 8/27/2009:3/12/2009
- 10/24/2016:11/13/2017
- 5/6/2014:10/30/2013
- 4/9/2013:4/18/2014
- 3/4/2010:4/1/2011
- 2/14/2022:8/12/2021
- 8/27/2023:9/30/2024
- 4/22/2018:4/28/2019
- 11/1/2021:5/10/2021
- 8/11/2012:2/19/2012
- 3/17/2015:10/4/2014
- 3/25/2017:10/16/2016
- 12/27/2014:12/20/2015
- 5/18/2016:4/29/2017
- 9/19/2028:9/1/2029
- 5/15/2011:6/13/2012
- 1/9/2018:1/1/2019
- 12/5/2016:5/25/2016
- 11/6/2007:5/11/2007
- 6/4/2012:12/5/2011
- 8/4/2023:8/5/2024
- 6/21/2021:6/13/2022
- 9/27/2014:9/20/2015
- 6/27/2023:7/18/2024
- 3/28/2015:9/25/2014
- 5/1/2009:4/25/2010
- 11/22/2019:1/4/2021
- 12/12/2015:6/19/2015
- 2/2/2015:8/12/2014
- 6/7/2014:6/24/2015
- 3/16/2007:3/4/2008
- 11/4/2017:11/13/2018
- 6/26/2014:7/6/2015
- 7/2/2012:1/2/2012
- 6/4/2012:12/10/2011
- 3/27/2018:9/15/2017
- 2/26/2014:1/29/2015
- 4/20/2012:3/9/2013
- 4/12/2011:5/14/2012
- 11/2/2012:11/18/2013
- 3/10/2016:9/14/2015
- 6/4/2015:5/21/2016
Advertisement
Add Comment
Please, Sign In to add comment