Question: Write a program that calculates the total and average sales over a period of years. The program will prompt the user to input the number
Write a program that calculates the total and average sales over a period of years. The program will prompt the user to input the number of years and the sales data for each month of each year. After collecting and processing the data, the program will print the average monthly sales and total annual sales.
Requirements:
User Input:
Prompt the user to enter the number of years they want to calculate sales for.
For each year, prompt the user to enter the sales amount for each month months per year
Input Validation:
Ensure the number of years entered is at least If not, display an error message and prompt the user to enter a valid number.
Ensure that all sales amounts are nonnegative. If a negative value is entered, display an error message and prompt the user to reenter the value.
Calculations:
Calculate the total sales for each year.
Calculate the average monthly sales over the entire period.
Methods:
ValueReturning Method : Create a method that takes the total sales and the number of months as parameters, and returns the average sales.
ValueReturning Method : Create a method that validates user input for years and sales amounts and returns the validated value.
NonValueReturning Method: Create a method that prints the total sales and average sales in a formatted manner.
Output:
Format all dollar amounts to two decimal places.
Print the total sales for the entire period.
Print the average monthly sales.
Sample Output:
Run :
Enter the number of years of sales to calculate:
Enter the sales, in dollars for each month.
Year month :
Year month :
Year month :
Year month :
Year month :
Year month :
Year month :
Year month :
Year month :
Year month :
Year month :
Year month :
Number of months:
Total Sales: $
Average annual sales: $
Run :
Enter the number of years of sales to calculate:
At least one year is needed to perform the calculation. Please try again.
Implementation Details:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
