Question

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 were no sales
on a day)
• Must use an array to store the days of the week that are printed in the prompt to the user and in the
final report
o A week is a work week, i.e. Monday-Friday, no Saturday or Sunday
• Must use an array to store the sales amounts for each day of the week
• There will be both definite and indefinite loop in the program
o You must determine and use the appropriate code for each situation, i.e. for with the definite
loop and while or do/while with the indefinite loop
• Must use printf() wherever appropriate, i.e. whenever printing a variable
• All money that is output must be printed with 2 places after the decimal and a dollar sign, no spaces, in
front of any money printed
• When printing the daily sales, must allow 14 spaces, left justified for printing days of week
• Must use additional static methods as indicated below here
• Your methods must be implemented as shown below here, i.e. must use the same name,
parameter list, and return type.
• You must be sure to do appropriate Javadoc documentation for all methods other than main().
• You may not use any field variables
• All other variables MUST be passed between methods and you must use return statements to return information from a method
The main() method will:
• Declare and create both arrays to be used
o Think about the best way to create the array to hold the days of the week
• Call on the other static methods as appropriate
• Print out the
o Highest amount of sales and when they occurred
o Lowest amount of sales and when they occurred
o The total amount of sales
o The average of all sales
The other static methods will be implemented as follows:

printTitle()
• Parameters: None
• Return type: void
• It will print the report title. You may choose the company name but it must be appropriate and pass a
PG-13 rating.

getSales()
• Parameters: A string array with the days of the week and an array of doubles to hold the sales
amounts
• Return type: void
• It will ask for the user for the sales for each day of the week. Must use the String array with the days of the week in the prompt to the user. It must also do data validation, using the isInvalid() method as part of that.

isInvalid()
• Parameters: integer that is the number to be test for validity
• Return type: boolean
• It will determine if the parameter is invalid or not, i.e. less than 1 or not, and will return a Boolean based on that.

printSales()
• Parameters: A string array with the days of the week, an array of doubles of the sales amounts
• Return type: void
• It will print the day of the week and the amount of sales for the day. Day of the week must print left justified with 14 spaces.
calculateHighest()

• Parameters: an array of doubles of the sales amounts
• Return type: int
• Will search the array for the highest amount of sales and return the index number of where that occurs.

calculateLowest()
• Parameters: an array of doubles of the sales amounts
• Return type: int
• Will search the array for the lowest amount of sales and return the index number of where that occurs.

findAverage()
• Parameters: an array of doubles of the sales amounts
• Return type: double
• Will calculate the average of the sales and return that amount. This method may call on one of the
other methods you are also creating for help in doing this if you feel that would be useful.
findTotal()
• Parameters: an array of doubles of the sales amounts
• Return type: double
• Will calculate the total of the sales and return that amount.

Dont understand how to do the static methods

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

Here is the code for the above assignment.

import java.util.Scanner;

public class Main

{

static void printTitle()

{

System.out.println("***************************************************");

System.out.println("****************Weekly Sales Report****************");

System.out.println("****************Hindustan Uniliver*****************");

}

static void getSales(String[] week, double[] sales)

{

Scanner sc = new Scanner(System.in);

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

System.out.println("Enter sales for " + week[i]);

double sale = sc.nextDouble();

if(isValid(sale)){

sales[i] = sale;

}else {

System.out.println("Please enter a valid sales number");

--i;

}

}

sc.close();

}

static boolean isValid(double number)

{

return number >= 0.0;

}

static void printSales(String[] week , double[] sales)

{

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

System.out.printf("%-14s" , week[i]);

System.out.println(sales[i]);

}

}

static int calculateHighest(double[] sales)

{

double highestSales = sales[0];

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

if(sales[i] > highestSales){

highestSales = sales[i];

}

}

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

if(sales[i] == highestSales){

return i;

}

}

return -1;

}

static int calculateLowest(double[] sales)

{

double lowestSales = sales[0];

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

if(sales[i] < lowestSales){

lowestSales = sales[i];

}

}

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

if(sales[i] == lowestSales){

return i;

}

}

return -1;

}

static double findAverage(double[] sales)

{

double sum = 0;

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

sum += sales[i];

}

return sum / (double)sales.length ;

}

static double findTotal(double[] sales)

{

double sum = 0;

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

sum += sales[i];

}

return sum ;

}

public static void main(String[] args) {

double[] sales = new double[5];

String[] week = new String[]{"Monday", "Tuesday", "Wednesday" , "Thrusday" , "Friday"};

printTitle();

printSales(week, sales);

getSales(week, sales);

int highestAmountIndex = calculateHighest(sales);

switch(highestAmountIndex)

{

case 0 : System.out.println("Highest Amount of sales is " + sales[highestAmountIndex] + " and occured on Monday");

break;

case 1: System.out.println("Highest Amount of sales is " + sales[highestAmountIndex] + " and occured on Tuesday");

break;

case 2: System.out.println("Highest Amount of sales is " + sales[highestAmountIndex] + " and occured on Wednesday");

break;

case 3: System.out.println("Highest Amount of sales is " + sales[highestAmountIndex] + " and occured on Thrusday");

break;

case 4: System.out.println("Highest Amount of sales is " + sales[highestAmountIndex] + " and occured on Friday");

break;

}

int lowestAmountIndex = calculateLowest(sales);

switch(lowestAmountIndex)

{

case 0 : System.out.println("Lowest Amount of sales is " + sales[lowestAmountIndex] + " and occured on Monday");

break;

case 1: System.out.println("Lowest Amount of sales is " + sales[lowestAmountIndex] + " and occured on Tuesday");

break;

case 2: System.out.println("Lowest Amount of sales is " + sales[lowestAmountIndex] + " and occured on Wednesday");

break;

case 3: System.out.println("Lowest Amount of sales is " + sales[lowestAmountIndex] + " and occured on Thrusday");

break;

case 4: System.out.println("Lowest Amount of sales is " + sales[lowestAmountIndex] + " and occured on Friday");

break;

}

System.out.println("The total amount of sales is " + findTotal(sales));

System.out.println("The Average sales of the week is " + findAverage(sales));

}

}

Screenshot of the test run

Feel free to comment on any doubt and give thumbs up.

Thank You!

Add a comment
Know the answer?
Add Answer to:
The XYZ Company needs you to write a program that will allow them to enter the...
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
  • 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...

  • Instructions We're going to create a program which will allow the user to add values to a list, p...

    Instructions We're going to create a program which will allow the user to add values to a list, print the values, and print the sum of all the values. Part of this program will be a simple user interface. 1. In the Program class, add a static list of doubles: private statie List<double> _values new List<double>) this is the list of doubles well be working with in the program. 2. Add ReadInteger (string prompt) , and ReadDouble(string prompt) to the...

  • In this lab, you will create one class named ArrayFun.java which will contain a main method...

    In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...

  • For the program described below, document your code well. Use descriptive identifier names. Use s...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • For the program described below, document your code well. Use descriptive identifier names. Use spaces and...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • Design a program that asks the user to enter a store's sales for each day of...

    Design a program that asks the user to enter a store's sales for each day of the week. The amounts should be stored in an array. Use a loop to calculate the total sales for the week and display the result. Be sure to attach your PYTHON code. No modularization required.

  • Design a program using Flowgorithm or any flowcharting software that asks the user to enter a...

    Design a program using Flowgorithm or any flowcharting software that asks the user to enter a store's sales for each day of the week. The amounts should be stored in an array. Use a loop to calculate the total sales for the week and display the result. PSEUDOCODE AND FLOWCHART IS REQUIRED FOR THIS CLASSWORK.

  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • This program will take advantage of methods written in the Help.java class First, you will write...

    This program will take advantage of methods written in the Help.java class First, you will write a new method in Help.java. This method will be named: addArray) and will accept an array of integers as input. This method will calculate the sum of all values in the array and return the resulting sum. Remember that the array being passed to the method may be of ANY length. (Use the existing methods in the Help.java class to help you remember how...

  • Java I - Write a program that will use static methods as described in the specifications below. U...

    Java I - Write a program that will use static methods as described in the specifications below. Utilizing the if and else statements, write a program which will calculate a commission based on a two-tiered commission plan of 2% and 5% paid on amounts of $10,000 or less, or over $10,000 in monthly sales by a sales force paid on a commission basis. Use the output specifications below. --- (Please make detailed comments so I can better understand the code....

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