Luninariel

Homework 3 instructions

Sep 24th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.26 KB | None | 0 0
  1. This assignment is about the following topics
  2.  
  3. Working with methods
  4. Working with objects
  5. Passing objects between methods as arguments and return values
  6. Stepping up the documentation
  7. Use the file lotto.txt. You can download it from the link below, or get it by going to http://www.molottery.com/gameHistory.do?method=loDisplay&order=asc (Links to an external site.)Links to an external site. and doing Ctrl-A followed by Ctrl-C and then pasting the text into a file in IntelliJ called lotto.txt.
  8.  
  9. Remember that the lotto.txt data file must be in the root of the Maven project folder. It should be at the same level as the pom.xml file in the project window.
  10.  
  11. The data is for lotto.txt is in a file. The lines of interest are the data lines that start with a date and end with the word "Million." A regex expression to extract this line is shown below.
  12.  
  13. String pattern = "(Sat)|(Wed), [JFMASOND][a-z]{2} \\d\\d, \\d{4}\\s+(\\d+-){5}\\d+\\s+\\$\\s*\\d\\.\\d\\d\\s+Million";
  14. A less aggressive but effective pattern would be
  15.  
  16. String pattern = "(Sat)|(Wed),.*Million";
  17. Your program should ask the user for a start date and an end date. The start date and the end date will be written in standard ISO 8601 format (Links to an external site.)Links to an external site..
  18.  
  19. The program should then read the file and print out the dates between the start and end dates, inclusive
  20.  
  21. Your program should follow the following pseudocode. You should write the main and write "stub" programs for any methods you have not yet written. Then fill in the methods one at a time.
  22.  
  23. main(String[] args)
  24. Scanner input;
  25. LocalDate startDate
  26. LocalDate endDate
  27.  
  28. int totalDataLines;
  29. startDate = getDate();
  30. endDate = getdate();
  31. int[] counts = new int[45];
  32.  
  33. print "Searching for draws from [[startDate]] to [[endDate]]"
  34.  
  35. totalDataLines = processFile(startDate, endDate, counts);
  36.  
  37. printf(Total date lines in the file: %d\n",totalDataLines)
  38.  
  39. print Program by your name
  40.  
  41. Documentation
  42.  
  43. We are going to ramp up the documentation standards on this program. We will start using JavaDoc comments. We will not insist on implementing every javadoc option.
  44.  
  45. Here are the requirements for this assignment
  46.  
  47. At the top of the program there should be a JavaDoc style comment about the program. An example is shown below.
  48. Each method except main() should have a javadoc comment just before the method.
  49. There should be one or more paragraphs explaining what the method does.
  50. There should be an @param line for each parameter in order they are declared
  51. If the method modifies a reference parameter the change should be explained.
  52. There should be an @return type
  53. If the method returns a value
  54. In order to avoid freaking people out too much, I am going to make the javadoc a separate assignment. However, when you turn in Homework 3 you should have the javadoc included.
  55.  
  56. lotto.txtPreview the document
  57.  
  58. Tips and hints:
  59.  
  60. Counting the occurrence of each ball is actually easy. It does NOT require a 44-level if statement!
  61. What is the difference between counts[i]++ and counts[i++]?
  62. This code might be handy:
  63. if(monthString.equals("Jan")
  64. month = 1;
  65. else if(monthString.equals("Feb")
  66. month = 2;
  67. else if(monthString.equals("Mar")
  68. ...
  69. Some sample output:
  70.  
  71.  
  72.  
  73. Start Date: 1900-01-01
  74. End Date: 2099-12-31
  75.  
  76. The highest count was 331
  77. Balls which occured 331 times:
  78. 21
  79.  
  80. The lowest count was 259
  81. Balls which occured 259 times:
  82. 9
  83.  
  84. The average count was 294.4
  85. Balls which occured 294 times:
  86. 19
  87. Balls which occured 295 times:
  88. 36
  89.  
  90. Ball frequencies:
  91. Ball 1 was drawn 293 times
  92. Ball 2 was drawn 283 times
  93. Ball 3 was drawn 288 times
  94. Ball 4 was drawn 276 times
  95. Ball 5 was drawn 281 times
  96. ...
  97.  
  98.  
  99.  
  100. For Overacheivers Only
  101. Optional: After you have the rest of the program working, add a feature that calculates the value of each ball. The value is calculated by taking the amount that week and dividing it by 6. Then instead of counting, sum the value of each ball. You will need an array of doubles to hold the value. Print out a report of the most valuable and least valuable balls as well as the average ball value.
  102.  
  103. If you really want to get fancy, only add the value of balls in a winning draw. You can only tell if a draw is a winner by seeing if the value drops to 1.0 million the next week.
  104.  
  105. Additional Pseudocode
  106. void getCounts(startDate, endDate, counts[])
  107. open "lotto.txt"
  108. while(input.hasNextLine())
  109. line = input.nextLine()
  110. if( line.matches(TARGETSTRING) )
  111. String[] parts = line.split("\\s+")
  112. //We don't really need to check how many parts there are because the
  113. //regex should have made sure there were 8 valid fields.
  114. LocalDate gameDate = makeLottoDate(yearPart, monthPart, dayPart)
  115.  
  116. if( isBetweenDates(startDate, endDate, gameDate) )
  117. count[0]++ //add one to the number of games counted (optional)
  118. String[] numberStrings = parts[4].split("-");
  119. for( i=0; i < numberStrings.length; i++)
  120. int number = numberStrings[part[i])
  121. count[number]++
  122.  
  123.  
  124. Another Data Run
  125. I did another run on just 4 games. Note that in this case the numbers that happen frequently or rarely are printed more than once. Also, I added a counter for the total number of games and stored it in counts[0] because it was not being used. This is optional because it was not part of the first version of this assignment
  126.  
  127. Start Date: 2017-09-02
  128. End Date: 2017-09-13
  129.  
  130. Total games counted: 4
  131. The highest count was 2
  132. Balls which occured 2 times:
  133. 4 31 38
  134.  
  135. The lowest count was 0
  136. Balls which occured 0 times:
  137. 2 3 5 6 9 10 11 13 14 15 17 18 19 20 22 24 25 26 27 28 32 36 43
  138.  
  139. The average count was 0.5
  140. Balls which occured 0 times:
  141. 2 3 5 6 9 10 11 13 14 15 17 18 19 20 22 24 25 26 27 28 32 36 43
  142. Balls which occured 1 times:
  143. 1 7 8 12 16 21 23 29 30 33 34 35 37 39 40 41 42 44
  144.  
  145. Ball frequencies:
  146. Ball 1 was drawn 1 times
  147. Ball 2 was drawn 0 times
  148. Ball 3 was drawn 0 times
  149. Ball 4 was drawn 2 times
  150. Ball 5 was drawn 0 times
  151. Ball 6 was drawn 0 times
  152. Ball 7 was drawn 1 times
  153. A run with "pathologic" data
  154.  
  155. Pathologic data that is somehow odd, but it should work. In this case the input data is pathologic because the start date is after the end date. It works, but all of the counts are 0.
  156.  
  157. Start Date: 2018-09-01
  158. End Date: 2017-09-15
  159.  
  160. Total games counted: 0
  161. The highest count was 0
  162. Balls which occured 0 times:
  163. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  164.  
  165. The lowest count was 0
  166. Balls which occured 0 times:
  167. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  168.  
  169. The average count was 0.0
  170. Balls which occured 0 times:
  171. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  172. Balls which occured 1 times:
  173.  
  174.  
  175. Ball frequencies:
  176. Ball 1 was drawn 0 times
  177. Ball 2 was drawn 0 times
  178. Ball 3 was drawn 0 times
  179. Ball 4 was drawn 0 times
  180. .
Advertisement
Add Comment
Please, Sign In to add comment