Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem a (PA2a.java) Write a program that reads in five whole numbers from the user. The program will calculate and output the following statistics about

image text in transcribed
image text in transcribed
Problem a (PA2a.java) Write a program that reads in five whole numbers from the user. The program will calculate and output the following statistics about the five numbers: The sum of all of the positive numbers (greater than zero). The sum of all of the non-positive numbers (less than or equal to zero). The sum of all five numbers. The average of all of the positive numbers (greater than zero). The average of all of the non-positive numbers (less than or equal to zero). The average of all five numbers. Note that your program must accept the five numbers in any order and cannot ask the user to enter the positive and non-positive numbers separately. You should start by calculating the sum and average of all five numbers. Be sure you get that working correctly and then move on to doing the calculations for the positive and non-positive numbers. You will need many variables to keep track of all the values, sums, and averages. Don't forget that to calculate the average of a set of numbers you sum them all up then divide by the number of values you added together. For example, if your program gets 3 positive numbers and 2 non- positive numbers, then you will divide the sum of the positive numbers by 3 to get the average and then divide the sum of the non-positive numbers by 2 to get the average of those numbers. This means you will have to keep track of how many positive numbers you read in and how many non-positive numbers you read in. Also note that you will need to write a lot of very similar looking pieces of code. Think about how to solve the problem for one or two numbers and then go from there to calculating the statistics for all five numbers. Finally, for sums, you should output just the number (e.g. 5 or 10) without any decimals (the sum of a set of integers is a sum!). However, for all averages, you must format the output to have two decimal places (even if they are both o), and round if necessary. The following represents a sample run of the program in which the user inputs on a single line"-11-22- 3" (without quotes). Note that the JUnit tests, and grading, will be very picky about exact spacing. spelling, capitalization, and number formatting. When only 1 positive number in five numbers, you need to use 'number' instead of 'numbers in the corresponding output text. Same rule for 1 non-positive number. Test case 1: Enter five whole numbers: -1 1 -2 2-3 The sum of the 2 positive numbers: 3 The sum of the 3 non-positive numbers: -6 The sum of the 5 numbers: -3 The average of the 2 positive numbers: 1.50 The average of the 3 non-positive numbers: -2.00 The average of the 5 numbers: -0.60 Test case 2 Enter five whole numbers: @ @ @ @ @ The sum of the positive numbers: The sum of the 5 non-positive numbers: @ The sum of the 5 numbers: 0 The average of the positive numbers: 0.00 The average of the 5 non-positive numbers: 0.00 The average of the 5 numbers: 0.00 It is 'number' not 'numbers' if only one positive input. Test case 3 Enter five whole numbers: 1 -1 -2 -3 The sum of the 1 positive number: 1 The sum of the 4 non-positive numbers: - 16 The sum of the 5 numbers: -9 The average of the 1 positive number: 1.00 The average of the 4 non-positive numbers: -2.50 The average of the 5 numbers: -1.80

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions