CSU Banner

CS 150, Fall 2017

Programming Assignment - P11

Music Singles: Top 15 Statistics

Due - December 7th, 2017 at 6:00pm

Late - December 8th, 2017 at 8:00am


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

Grading Criteria


Submit P11.java to Checkin.


CS Banner
CS Building