Luninariel

Homework 2 instructions

Sep 15th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. Create a Java project in Maven.
  2.  
  3. 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.
  4.  
  5. The file input.txt contains lines of data. In the sample file provided, The lines have the following characteristics
  6.  
  7. Lines are "colon delimited"
  8. Valid lines contain two fields. (Invalid lines should be ignored when processing)
  9. The number of lines is unknown in advance
  10. Dates are in "standard" US format of month/day/year
  11. If there are exactly two dates on a line, those dates may be assumed to be valid dates.
  12. For each line of text in the file:
  13.  
  14. Split the line of text on the tab.
  15. If there are exactly two fields on the line, process the line. Ignore lines with other than two fields.
  16. Use a method to split the date into the month, day, and year fields. The method should return an instance of the LocalDate class.
  17. 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.
  18. At the end of the program print the number of date-pairs processed.
  19.  
  20.  
  21.  
  22. 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.
  23.  
  24.  
  25.  
  26. Pseudocode
  27.  
  28. main()
  29. Scanner input = openFile("input.txt)
  30. int pairsProcessed
  31. pairsProcessed = processDates(input)
  32. close input
  33. print pairsProcessed
  34.  
  35. processDates(Scanner input)
  36. int n = 0;
  37. while input has more lines
  38. line = input.nextLine()
  39. String[] dates = line.split(":");
  40. if (dates.length == 2)
  41. n++
  42. LocalDate a = makeDate(dates[0]);
  43. LocalDate b = makeDate(dates[1]);
  44. if( a is before b) Note that (a < b) will not work!
  45. print a b
  46. else
  47. print b a
  48. return n;
  49.  
  50. makeDates(String s)
  51. Localdate date = null;
  52. String[] parts = split s on the "/" character
  53. int month = Integer.parseInt(parts[0])
  54. int day = ...
  55. int year=...
  56. date = LocalDate.of( ... )
  57. return date
  58. Sample test data
  59.  
  60. 4/10/2017:3/10/2018
  61. 4/2/2011:2/29/2004
  62. 12/29/2011:12/29/2011
  63. 4/20/2011:11/13/2010
  64. 2/12/2019:2/26/2020
  65. 10/24/2018:11/29/2019
  66. 5/27/2013:11/22/2012
  67. 11/1/2010:11/2/2011
  68. 1/19/2020:8/7/2019
  69. 7/12/2011:6/20/2012
  70. 12/14/2013:6/12/2013
  71. 3/1/2013:8/10/2012
  72. 8/26/2017:8/9/2018
  73. 1/18/2014:1/11/2015
  74. 7/4/2014:7/10/2015
  75. 7/1/2017:6/17/2018
  76. 2/15/2021:2/1/2022
  77. 3/1/2014:4/3/2015
  78. 10/28/2010:11/24/2011
  79. 10/12/2022:4/17/2022
  80. 4/12/2014:4/13/2015
  81. 11/17/2012:5/22/2012
  82. 1/15/2020:7/23/2019
  83. 4/4/2017:9/25/2016
  84.  
  85. 3/1/2017:3/13/2018
  86. 7/17/2013:8/1/2014:4/4/2017:9/25/2016
  87. 12/25/2010:12/17/2011
  88. 7/25/2012
  89. 12/14/2017:12/3/2018
  90. 8/27/2015:3/6/2015
  91. 7/16/2008:12/21/2007
  92. 4/20/2017:4/14/2018
  93. 4/6/2017:3/13/2018
  94. 12/3/2013:11/15/2014
  95. 2/28/2018:3/28/2019
  96. 9/17/2020:9/29/2021
  97. 3/4/2009:3/4/2010
  98. 2/10/2014:2/11/2015
  99. 5/6/2013:11/4/2012
  100. 5/1/2009:10/31/2008
  101. 9/8/2020:2/29/2020
  102. 8/25/2014:9/6/2015
  103. 11/23/2011:5/3/2011
  104. 6/17/2015:12/24/2014
  105. 4/15/2017:10/9/2016
  106. 5/18/2016:4/12/2017
  107. 2/27/2013:9/11/2012
  108. 2/4/2027:1/20/2028
  109. 11/11/2019:5/3/2019
  110. 4/6/2016:10/7/2015
  111. 1/25/2016:7/27/2015
  112. 10/14/2012:4/29/2012
  113. 3/12/2011:2/27/2012
  114. 11/22/2012:11/1/2013
  115. 6/15/2014:5/22/2015
  116. 8/27/2009:3/12/2009
  117. 10/24/2016:11/13/2017
  118. 5/6/2014:10/30/2013
  119. 4/9/2013:4/18/2014
  120. 3/4/2010:4/1/2011
  121. 2/14/2022:8/12/2021
  122. 8/27/2023:9/30/2024
  123. 4/22/2018:4/28/2019
  124. 11/1/2021:5/10/2021
  125. 8/11/2012:2/19/2012
  126. 3/17/2015:10/4/2014
  127. 3/25/2017:10/16/2016
  128. 12/27/2014:12/20/2015
  129. 5/18/2016:4/29/2017
  130. 9/19/2028:9/1/2029
  131. 5/15/2011:6/13/2012
  132. 1/9/2018:1/1/2019
  133. 12/5/2016:5/25/2016
  134. 11/6/2007:5/11/2007
  135. 6/4/2012:12/5/2011
  136. 8/4/2023:8/5/2024
  137. 6/21/2021:6/13/2022
  138. 9/27/2014:9/20/2015
  139. 6/27/2023:7/18/2024
  140. 3/28/2015:9/25/2014
  141. 5/1/2009:4/25/2010
  142. 11/22/2019:1/4/2021
  143. 12/12/2015:6/19/2015
  144. 2/2/2015:8/12/2014
  145. 6/7/2014:6/24/2015
  146. 3/16/2007:3/4/2008
  147. 11/4/2017:11/13/2018
  148. 6/26/2014:7/6/2015
  149. 7/2/2012:1/2/2012
  150. 6/4/2012:12/10/2011
  151. 3/27/2018:9/15/2017
  152. 2/26/2014:1/29/2015
  153. 4/20/2012:3/9/2013
  154.  
  155. 4/12/2011:5/14/2012
  156. 11/2/2012:11/18/2013
  157. 3/10/2016:9/14/2015
  158. 6/4/2015:5/21/2016
Advertisement
Add Comment
Please, Sign In to add comment