Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This assignment is about the following topics
- Working with methods
- Working with objects
- Passing objects between methods as arguments and return values
- Stepping up the documentation
- 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.
- 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.
- 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.
- String pattern = "(Sat)|(Wed), [JFMASOND][a-z]{2} \\d\\d, \\d{4}\\s+(\\d+-){5}\\d+\\s+\\$\\s*\\d\\.\\d\\d\\s+Million";
- A less aggressive but effective pattern would be
- String pattern = "(Sat)|(Wed),.*Million";
- 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..
- The program should then read the file and print out the dates between the start and end dates, inclusive
- 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.
- main(String[] args)
- Scanner input;
- LocalDate startDate
- LocalDate endDate
- int totalDataLines;
- startDate = getDate();
- endDate = getdate();
- int[] counts = new int[45];
- print "Searching for draws from [[startDate]] to [[endDate]]"
- totalDataLines = processFile(startDate, endDate, counts);
- printf(Total date lines in the file: %d\n",totalDataLines)
- print Program by your name
- Documentation
- 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.
- Here are the requirements for this assignment
- At the top of the program there should be a JavaDoc style comment about the program. An example is shown below.
- Each method except main() should have a javadoc comment just before the method.
- There should be one or more paragraphs explaining what the method does.
- There should be an @param line for each parameter in order they are declared
- If the method modifies a reference parameter the change should be explained.
- There should be an @return type
- If the method returns a value
- 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.
- lotto.txtPreview the document
- Tips and hints:
- Counting the occurrence of each ball is actually easy. It does NOT require a 44-level if statement!
- What is the difference between counts[i]++ and counts[i++]?
- This code might be handy:
- if(monthString.equals("Jan")
- month = 1;
- else if(monthString.equals("Feb")
- month = 2;
- else if(monthString.equals("Mar")
- ...
- Some sample output:
- Start Date: 1900-01-01
- End Date: 2099-12-31
- The highest count was 331
- Balls which occured 331 times:
- 21
- The lowest count was 259
- Balls which occured 259 times:
- 9
- The average count was 294.4
- Balls which occured 294 times:
- 19
- Balls which occured 295 times:
- 36
- Ball frequencies:
- Ball 1 was drawn 293 times
- Ball 2 was drawn 283 times
- Ball 3 was drawn 288 times
- Ball 4 was drawn 276 times
- Ball 5 was drawn 281 times
- ...
- For Overacheivers Only
- 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.
- 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.
- Additional Pseudocode
- void getCounts(startDate, endDate, counts[])
- open "lotto.txt"
- while(input.hasNextLine())
- line = input.nextLine()
- if( line.matches(TARGETSTRING) )
- String[] parts = line.split("\\s+")
- //We don't really need to check how many parts there are because the
- //regex should have made sure there were 8 valid fields.
- LocalDate gameDate = makeLottoDate(yearPart, monthPart, dayPart)
- if( isBetweenDates(startDate, endDate, gameDate) )
- count[0]++ //add one to the number of games counted (optional)
- String[] numberStrings = parts[4].split("-");
- for( i=0; i < numberStrings.length; i++)
- int number = numberStrings[part[i])
- count[number]++
- Another Data Run
- 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
- Start Date: 2017-09-02
- End Date: 2017-09-13
- Total games counted: 4
- The highest count was 2
- Balls which occured 2 times:
- 4 31 38
- The lowest count was 0
- Balls which occured 0 times:
- 2 3 5 6 9 10 11 13 14 15 17 18 19 20 22 24 25 26 27 28 32 36 43
- The average count was 0.5
- Balls which occured 0 times:
- 2 3 5 6 9 10 11 13 14 15 17 18 19 20 22 24 25 26 27 28 32 36 43
- Balls which occured 1 times:
- 1 7 8 12 16 21 23 29 30 33 34 35 37 39 40 41 42 44
- Ball frequencies:
- Ball 1 was drawn 1 times
- Ball 2 was drawn 0 times
- Ball 3 was drawn 0 times
- Ball 4 was drawn 2 times
- Ball 5 was drawn 0 times
- Ball 6 was drawn 0 times
- Ball 7 was drawn 1 times
- A run with "pathologic" data
- 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.
- Start Date: 2018-09-01
- End Date: 2017-09-15
- Total games counted: 0
- The highest count was 0
- Balls which occured 0 times:
- 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
- The lowest count was 0
- Balls which occured 0 times:
- 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
- The average count was 0.0
- Balls which occured 0 times:
- 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
- Balls which occured 1 times:
- Ball frequencies:
- Ball 1 was drawn 0 times
- Ball 2 was drawn 0 times
- Ball 3 was drawn 0 times
- Ball 4 was drawn 0 times
- .
Advertisement
Add Comment
Please, Sign In to add comment