Assignment #6

Assignment #6

Assignment #6

Average Salary of Major League Baseball Players

Create an application that calculates the average and highest salary of Major League Baseball players in 2011 and 2012.

When the user clicks a button, the application reads a csv file (see the attached Salaries.csv) and calculates the average and the highest salary as follows.

Reads each line of the file data using a while loop (start from the second row)

Splits each row by using a delimiter (‘,’) into five tokens

Reads year and salary information – they are 1st and 5th tokens and you will need to convert them to integer

Calculates the average and gets the highest.

To calculate the average, you will need to get the sum of the salaries in 2011 and 2012 and then calculate the average after the loop

To get the highest, you will need to declare a variable for the highest salary before the loop and updates the highest salary variable when new salary is greater than the previous highest salary. By doing so, you will be able to get the highest salary at the end of the loop.

After the loop, average and highest salary of each year should be displayed as follows.  The csv file is attached.
Powered by