Question

Create a modular program using structured programming to store the amount of money a local store...

Create a modular program using structured programming to store the amount of money a local store made in sales for each day of the past week. The user will be given the option to enter an amount for the next day, compute the average, find the highest amount, find the lowest amount, or print all the information including the daily sales with the average, highest, and lowest amount. When the user chooses an option to enter an amount for the next day, the user will be prompted to enter the amount. The amount must be greater than or equal to 0. If a negative amount is entered the user will be given an error message and prompted to enter a value greater than or equal to 0 for the same day. Once the user has entered a value greater than or equal to 0, that amount will be saved. If the user attempts to enter more than seven days the program will give the user an error message informing them the information for the entire week has already been entered. If the user chooses to compute the average, find the highest amount, or find the lowest amount that amount will be printed to screen. This program will only have one class which has static methods and uses a single array of size seven to save the daily sales amounts. There should be a main method, a static method to get an amount from the user, compute the average, find the lowest amount, find the highest amount, and print out all the information.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

WeeklySales.java

import java.util.Scanner;

public class WeeklySales {

public static void main(String[] args) {

// Declaring and initializing an array

double sales[] = new double[7];

int i = 0;

double value = 0;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

System.out.print("Enter the sales amount :$");

while (true) {

while (true) {

if(i<sales.length)

{

value = sc.nextDouble();

}

if (value < 0) {

System.out.println("** Invalid.Must be greater than zero **");

System.out.print("Enter the sales amount :$");

} else {

if(i<sales.length)

{

sales[i] = value;

i++;

}

break;

}

}

System.out.print("Do you want to enter next day sales amount (y/n)?");

char ch = sc.next(".").charAt(0);

if (ch == 'Y' || ch == 'y') {

if (i < sales.length) {

System.out.print("Enter the sales amount :$");

} else {

System.out.println("** information for the entire week has already been entered **");

}

continue;

} else {

break;

}

}

//Displaying the output

System.out.printf("Average of weekly sales :$%.2f\n",computeAverage(sales));

System.out.printf("Highest Sales amount :$%.2f\n",findHighest(sales));

System.out.printf("Lowest Sales amount :$%.2f\n",findLowest(sales));

}

//This method will find the lowest element in the array

private static double findLowest(double[] sales) {

double min=sales[0];

for(int i=0;i<sales.length;i++)

{

if(min>sales[i])

min=sales[i];

}

return min;

}

//This method will find the highest element in the array

private static double findHighest(double[] sales) {

double max=sales[0];

for(int i=0;i<sales.length;i++)

{

if(max<sales[i])

max=sales[i];

}

return max;

}

//This method will calculate the average of all elements

private static double computeAverage(double[] sales) {

double sum=0;

double min=sales[0];

for(int i=0;i<sales.length;i++)

{

sum+=sales[i];

}

return (sum/sales.length);

}

}

_______________________

Output:

Enter the sales amount :$3400
Do you want to enter next day sales amount (y/n)?y
Enter the sales amount :$5400
Do you want to enter next day sales amount (y/n)?y
Enter the sales amount :$-7800
** Invalid.Must be greater than zero **
Enter the sales amount :$7800
Do you want to enter next day sales amount (y/n)?y
Enter the sales amount :$6100
Do you want to enter next day sales amount (y/n)?y
Enter the sales amount :$8800
Do you want to enter next day sales amount (y/n)?y
Enter the sales amount :$6600
Do you want to enter next day sales amount (y/n)?y
Enter the sales amount :$4300
Do you want to enter next day sales amount (y/n)?y
** information for the entire week has already been entered **
Do you want to enter next day sales amount (y/n)?y
** information for the entire week has already been entered **
Do you want to enter next day sales amount (y/n)?n
Average of weekly sales :$6057.14
Highest Sales amount :$8800.00
Lowest Sales amount :$3400.00

________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Create a modular program using structured programming to store the amount of money a local store...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The XYZ Company needs you to write a program that will allow them to enter the...

    The XYZ Company needs you to write a program that will allow them to enter the weekly sales for a salesperson and then the program will calculate things such as most sales (and what day on which they happened), least sales (and day on which they happened), total sales, and daily average. The program will need to do the following: • Validate the user input to ensure that it is not less than 0.0 (0.0 will be acceptable if there...

  • Develop a Java program that will store data in the form of daily average temperatures for...

    Develop a Java program that will store data in the form of daily average temperatures for one week. Store the day and average temperature in two different arraylists. Your program should prompt the user for the day of the week (Monday through Sunday) and display both the day and temperature for each day. If “week” is entered, the output for your program should provide the temperature for each day and the weekly average. Use the looping and decision constructs in...

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

  • In-Class Assignment 4 (15 pts) Structured Programming, if Statements 1. Write a program that prompts the...

    In-Class Assignment 4 (15 pts) Structured Programming, if Statements 1. Write a program that prompts the user to enter a value. Print a message stating whether the input value is less than zero or greater than zero or equal to zero. Submit a screenshot of output for each case. See below for sample output Microsoft Visual Studio Debug Console Microsoft Visual Studio Debug Console Microsoft Visual Studio Debug Console Enter a value 5 Enter a value you entered zero. Enter...

  • Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sale...

    Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sales people (SalesPerson.java) The information needed are: D Number integer Month 1 Sales Amount-Double Month 2 Sales Amount-Double Month 3 Sales Amount-Double Write a Java program that allows you to store the information of any salesperson up to 20 While the user...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • In C++ 2. Write a program that allows the user to enter a series of positive...

    In C++ 2. Write a program that allows the user to enter a series of positive numbers between 1 and 100 and displays the smallest and largest of the numbers entered. The program should not store the numbers that were entered, only keep track of the smallest and largest ones. The program should continue accepting numbers until the value 0 is entered and then display the results. If a number out of range is entered, tell the user it is...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • please help with this. You must create a sales tracking program named SalesTracking.java. This program must...

    please help with this. You must create a sales tracking program named SalesTracking.java. This program must track monthly sales as well as compute average yearly sales, total sales for the year, and which month had the highest sales and which month had the lowest sales. The program should prompt the user for the sales for each month starting with January. After all the monthly sales have been entered, your program should have methods that do the following. getSales(): This method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT