Write a program that reads integers, one per line, and displays their sum. Also, display all the numbers read, each with an annotation giving its percentage contribution to the sum. Use a method that takes the entire array as one argument and returns the sum of the numbers in the array. Hint: Ask the user for the number of integers to be entered, create an array of that length, and then fill the array with the integers read. A possible dialogue between the program and the user follows:
How many numbers will you enter?
4
Enter 4 integers, one per line:
2
1
1
2
The sum is 6.
The numbers are:
2, which is 33.3333% of the sum.
1, which is 16.6666% of the sum.
1, which is 16.6666% of the sum.
2, which is 33.3333% of the sum.
This project is very much like ArrayOfTemperatures, Listing 7.1. Just add code to prompt for and read in the length of the array, and, instead of finding the average, divide each element by the sum to obtain its percent.
See the code in PercentOfSum.java.
You might also like to view...
Add server-side form validation to the order form in the bookstore case study. Check that the credit-card expiration date is after today’s date. If not, redirect the user to error.py with the message "Expired credit card." Also, make all fields in the form required fields. When the user does not supply data for all required fields, redirect the user back to order.py.
What will be an ideal response?
The 7× ________ guideline is a general PowerPoint rule
Fill in the blank(s) with correct word
The _____ function replaces text in a text string.?
A. REPLACE B. ?SEARCH & REPLACE C. ?SUBSTITUTE D. ?STRING
What is the difference between overriding a method and overloading a method with respect to method signatures?
What will be an ideal response?