# CS 150, Fall 2017

## Music Singles: Top 15 Statistics

#### Objectives of this Assignment

1. Use methods to calculate statistics on song information,
2. review the purpose behind different method signatures, and
3. review file input/output.

#### Instructions

Create a Java program called P11 with a class named P11. Please complete the code required from this week's lab first if you have not already done so. All of the Java code you write should be contained in the P11 class. To complete the assignment, fill in the required code for the three remaining methods, as well as add more code to main() and writeFile().

Part One
1. Start by writing the code necessary in averageYearReleased().
2. First, declare three integer variables, one to represent the sum of release years, another to count the number of release years, and one for the resulting average. Initialize all to zero.
3. Write a for loop that iterates over `songArray`. You will need to look at the input file to determine where your for loop should start and how to change your index variable per loop iteration.
4. Inside the loop, successively add the values of only the release years and increment your counter variable.
5. Because `songArray` is an array of Strings, you will need to parse each release year to an integer value. Do so by using the parseInt() method of the Integer wrapper class: `Integer.parseInt(String argument)`
6. After your for loop, calculate the average and return it.
7. Next, move to averageChartNumber().
8. First, declare three integer variables, one to represent the sum of chart placements, another to count the number of chart placements, and one for the resulting average. Initialize all to zero.
9. Write a for loop that iterates over `songArray`. You will need to look at the input file to determine where your for loop should start and how to change your index variable per loop iteration.
10. Inside the loop, successively add the values of only the chart placement values and increment your counter variable.
11. Because `songArray` is an array of Strings, you will again need to parse each song's chart value to an integer value.
12. After your for loop, calculate the average and return it.

13. Part Two
14. Now finish the code necessary for determineRangeOfYears(). Notice the return type of this method is different than the average methods.
15. First, declare and initialize two integers to represent the minimum and maximum year from the input file. These two variables with both be initialized to the first year listed in the file which you should access via `songArray`. Again, you will need to parse the value from the array, since `songArray` is a String array.
16. Second, declare and initialize an integer array to a size of two. This array with hold the minimum and maximum year values.
17. Now write a for loop that iterates over `songArray`. You will need to look at the input file to determine where your for loop should start and how to change your index variable per loop iteration.
18. Inside the for loop, you will need two conditionals. One should check if the current element of `songArray` is less than the current value of the minimum year. The other will check if the current element of `songArray` is greater than the current value of the maximum year.
19. Utilize parsing again to do this comparison - the program should check an integer against another integer.
20. If either of the above conditionals are true, reassign the minimum or maximum year appropriately. You will need to parse the value in `songArray` again during the reassignment.
21. After the for loop, set the first element of your local integer array to the minimum year and the second element to the maximum year.
22. Then, return the integer array.

23. Part Three
24. The last part of this assignment requires you to write several more lines of code main() and writeFile().
25. In writeFile() add the following three prompts along with the associated variables:
```Average Year Released:
Average Chart Placement:
Range of Release Years: ```
26. After the Range of Release Years prompt, you must also include a hyphen between the year values with no spaces. This line should also include a new line character.
27. Now move to main() where you will finish writing the missing method calls and assignments.
28. Before the call to writeFile(), make calls to averageYearReleased(), averageChartNumber(), and determineRangeOfYears(). Assign all three method calls to the appropriate local variables in main().

#### Output File Contents

```TOP 15 STATISTICS
Average Title Length: 15
Average Year Released: 1967
Average Chart Placement: 9
Range of Release Years: 1958-1991
```

#### Specifications

• Work on your own, as always.
• The name of the source code file must be exactly
` P11.java `
• Name the file exactly - upper and lower case matters!
• Comments at the top as shown above.
• Assignments should be implemented using Eclipse.
• Assignments should be implemented using Java, version 1.8.
• Make sure your code runs on machines in the CSB 120 lab.
• Turn in through the Checkin tab.
• Read the syllabus for the late policy.
• We will be checking programs for plagiarism, so please don't copy from anyone else.

• 100 points for perfect submission.
• 0 points for no submission, will not compile, submitted class file, etc.
• Preliminary Tests
Preliminary testing tests lines 1-5 .
• testCompile: checks that program compiles. (0 points)
• lineTests: verify correct output based on String method used.
• test1:
• test2:
• test3:
• test4:
• test5:
• Final Tests
Final testing tests lines 6-8.
• test8:
• test9:
• test10:
• Final grading includes the preliminary tests.

Submit P11.java to Checkin.