Question

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 prompts the users for the sale for each month. The return value for this method will be the amount that the user entered. This amount should be stored and returned into the corresponding location in the monthlySales array. For example, January sales should be stored in the first location, February sales should be stored in the second location, and so forth. This method should be enclosed in a loop to facilitate this process.computeTotalSales(monthlySales): This method receives the monthly sales array as an argument and returns the total sales of the year.computeAverageSales(monthlySales): This method receives the monthly sales array as an argument and returns the average sales for the year.computeHighestMonth(monthlySales): This method receives the monthly sales array as an argument. This method will search and compare the values of the monthly sales array for the highest value. Once the highest value has been determined, it will store the value in the value that corresponds with the index of that month. The method will return the index of the month with the highest value.computeLowestMonth(monthlySales): This method receives the monthly sales array as an argument. This method will search and compare the values of the monthly sales array for the lowest value. Once the lowest value has been determined, it will store the value in the value that corresponds with the index of that month. The method will return the index of the month with the lowest value.displaySaleInfo(totalSales, averageSales, highestMonth, highestSales, lowestMonth, lowestSales): This method will receive the total yearly sales, average monthly sale, the month with the highest sales, as well as the sales for that month and the month with the lowest sales. This method will display all of the data it received as arguments.All methods must be called from the main method. Sales amounts should be rounded to two decimal places. You should use parallel arrays. Your first array (monthArray) should be initialized with all of the months. This array should have 12 locations of course. Your other array should be named monthlySales. Like your monthArray, this array should be 12 locations and be populated with the getSales( ) method.

Your monthArray should have the following values.

monthArray

JANUARYFEBRUARYMARCH...............NOVEMBERDECEMBER

 You should demonstrate the use of loop and decision structures also

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

import java.util.Scanner;

public class SalesTracking {

   public static double getSales() {
       Scanner in = new Scanner(System.in);
       return in.nextInt();
   }

   public static double computeTotalSales(double monthlySales[]) {
       double sum = 0;
       for (int i = 0; i < monthlySales.length; ++i) {
           sum += monthlySales[i];
       }
       return sum;
   }

   public static double computeAverageSales(double monthlySales[]) {
       double sum = 0;
       for (int i = 0; i < monthlySales.length; ++i) {
           sum += monthlySales[i];
       }
       return sum / monthlySales.length;
   }

   public static int computeHighestMonth(double monthlySales[]) {
       int ind = 0;
       for (int i = 1; i < monthlySales.length; ++i) {
           if (monthlySales[i] > monthlySales[ind]) {
               ind = i;
           }
       }
       return ind;
   }

   public static int computeLowestMonth(double monthlySales[]) {
       int ind = 0;
       for (int i = 1; i < monthlySales.length; ++i) {
           if (monthlySales[i] < monthlySales[ind]) {
               ind = i;
           }
       }
       return ind;
   }

   public static void displaySaleInfo(double totalSales, double averageSales,
           String highestMonth, double highestSales, String lowestMonth,
           double lowestSales) {
       System.out.printf("Total Sales: %.2f\n", totalSales);
       System.out.printf("Average Sales: %.2f\n", averageSales);
       System.out.printf("Highest Sales amount is %.2f on %s\n", highestSales,
               highestMonth);
       System.out.printf("Lowest Sales amount is %.2f on %s\n", lowestSales,
               lowestMonth);
   }

   public static void main(String args[]) {
       double monthlySales[] = new double[12];
       String monthArray[] = { "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY",
               "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER",
               "DECEMBER" };
       for (int i = 0; i < monthlySales.length; ++i) {
           System.out.print("Sales for " + monthArray[i] + ": ");
           monthlySales[i] = getSales();
       }
       double totalSales = computeTotalSales(monthlySales);
       double averageSales = computeAverageSales(monthlySales);
       int maxIndex = computeHighestMonth(monthlySales);
       int minIndex = computeLowestMonth(monthlySales);
       displaySaleInfo(totalSales, averageSales, monthArray[maxIndex],
               monthlySales[maxIndex], monthArray[minIndex],
               monthlySales[minIndex]);
   }
}

Add a comment
Know the answer?
Add Answer to:
please help with this. You must create a sales tracking program named SalesTracking.java. This program must...
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
  • You must create a Java class named TenArrayMethods in a file named TenArrayMethods.java. This class must...

    You must create a Java class named TenArrayMethods in a file named TenArrayMethods.java. This class must include all the following described methods. Each of these methods should be public and static.Write a method named getFirst, that takes an Array of int as an argument and returns the value of the first element of the array. NO array lists. Write a method named getLast, that takes an Array of int as an argument and returns the value of the last element...

  • Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a...

    Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a method named FillArray to interactively fill the array with any number of values up to 10 or until a sentinel value (999) is entered. If an entry is not an integer, reprompt the user. Call a second method named Statistics that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and...

  • Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This...

    Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This method should accept a two-dimensional array as its argument and return the total of all the values in the array. Write overloaded versions of this method that work with int , double , and long arrays. (A) getAverage . This method should accept a two-dimensional array as its argument and return the average of all the values in the array. Write overloaded versions of...

  • Please help with program this. Thank you so much in advance! Create a Java program which...

    Please help with program this. Thank you so much in advance! Create a Java program which implements a simple stack machine. The machine has 6 instructions Push operand Puts a value on the stack. The operand is either a floating point literal or one of 10 memory locations designated MO M9 Pop operand Pops the value on the top of the stack and moves it to the memory location MO-M9 Add Pops the top two values off the stack, performs...

  • Assignment 06 – Ten Array Methods You must work in alone on this assignment. Do not...

    Assignment 06 – Ten Array Methods You must work in alone on this assignment. Do not use any Java language features we have not cover so far in this course. Assignment Objectives After completing this assignment the student should be able to:  Declare and instantiate arrays  Access array elements by index  Use loops and decisions to manipulate arrays and array elements  Write methods that manipulate arrays  Write methods that take array arguments  Write methods...

  • Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write...

    Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write a method (getData) that would ask user to enter a set of data – for example, five student names and corresponding scores. This program should also have the following methods:     getSum. This method should accept a studentScore array as its argument and return the sum of the values in the array.     getAverage. This method should accept a studentScore array as its argument...

  • This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array...

    This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. .getAverage. This method should accept a two-dimensional array as its argument and return...

  • You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must c...

    You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must contain: getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user may press Cancel or enter an empty string to...

  • In this homework, create two arrays – studentName and studentScore (String and Int types). Write a...

    In this homework, create two arrays – studentName and studentScore (String and Int types). Write a method (getData) that would ask user to enter a set of data – for example, five student names and corresponding scores. This program should also have the following methods:     getSum. This method should accept a studentScore array as its argument and return the sum of the values in the array.     getAverage. This method should accept a studentScore array as its argument and...

  • Can you help me to write a Java code for this: The program must satisfy the...

    Can you help me to write a Java code for this: The program must satisfy the following requirements: The program should ask the user the following information The site names for 6 locations (into an array) The cash donation for 6 locations (into an array) The food donations in pounds for 6 locations (into an array) Is there another test they want to process, meaning do they want to run the program again? Based on the input, the program will...

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