BookRating Program
Description
This program uses two arrays to store title and rating for 5 books, and uses several methods to do the following:
Fill in the arrays with user input data
Calculate the average rating
Find the the book with the highest rating (assume there is no tie)
Print all 5 books' title and rating
Calculate the average rating
Find the the book with the highest rating (assume there is no tie)
Print all 5 books' title and rating
Associated Concepts:
Array
Algorithm:
main method:
populateArray method definition:
printArray method definition:
sumArray method definition:
indexOfHighestRating method definition:
Create two arrays to store 5 books information, title and rating
Call methods to:
Array of String to store titles
Array of double to store ratings
Array of double to store ratings
Call methods to:
Populate the arrays with user input data
Print the array elements
Calculate the total rating
Find the index of the book with the highest rating and print the result
Print the average rating
Print the array elements
Calculate the total rating
Find the index of the book with the highest rating and print the result
Print the average rating
populateArray method definition:
For i = 0 to last index of array cell
Input title and rating from the keyboard
Assign them to the array cells at i
Assign them to the array cells at i
printArray method definition:
For i = 0 to last index of array cell
Print array elements at i
sumArray method definition:
Declare variable sum and initialize it to 0
For i = 0 to last index of array cell
return sum
For i = 0 to last index of array cell
Add the current rating at i to sum
return sum
indexOfHighestRating method definition:
Declare variable maxIndex and assign it to 0
(Assume the first element is the highest)
For i = 1 to last index of array cell
return maxIndex
For i = 1 to last index of array cell
If the current element at i is greater than
the current highest element
Update maxIndex to the current index i
Update maxIndex to the current index i
return maxIndex