QuestionQuestion

Transcribed TextTranscribed Text

Final Project: Sales Forecasting Purpose: The purpose of this project is for you to demonstrate your ability to design and code a program that creates an ArrayList of objects and stores it in a binary file. Then, design and code an application that reads the ArrayList from the file, uses it to recalculate and change some of its data, and rewrites it to another binary file. This is a final-course capstone project in which you may need to employ all the techniques you have learned in this course. Scenario: Joe owns a small grocery store. It has become very popular with the locals and is beginning to sell more product than ever before. As a result, the store is beginning to experience more out-of-stock and overstock situations than before. After some investigation, Joe realizes that the problem lies in his and his grocery managers’ inability to accurately predict sales from week to week. Recently, Joe learned of a relatively simple method to forecast future sales amounts and would like to experiment with it for a few items before committing the entire store to the process. He and his managers selected five items to try out the new process. His friend (you) offered to create the two programs to simulate the forecasting operation to be used to manage the store inventory for the five items. The process is called “Exponential Smoothing.” It uses a “smoothing” factor that allows a user to increase or decrease the sensitivity to each new sales value. The factor controls the calculation’s result based on whether the sales are stable, small changes from week to week, or volatile, high swings from week to week. Joe knows that stable sales tend to create overstock situations and volatile sales tend to cause out-of-stock situations. He hopes to remedy both problems with this new technique. Specifications: This assignment requires you to design and code two programs: 1. A program that creates an ArrayList with the file sales records and writes it to a binary file. 2. The main (application) program that reads the ArrayList from the binary file, calculates the new forecast, modifies each record in the ArrayList, and writes the ArrayList to another binary file. Final Project: Sales Forecasting You may put both programs in one project, or separate them into two projects: • If you intend to have only one project, it must contain both program and the Sales class file. In this case, the project will contain both sales1.dat and sales2.dat files. Name this project SalesForecasting. • If two projects, both require their specific program and the Sales class. The sales1.dat file created in the creation project will need to be copied into the second (main application) project. Name the project that creates the sales1 file SalesCreation; name the main (application) project SalesForecasting. Step 1: Design and code a Sales class that contains a product number (int), a product description (String), smoothing factor (double), previous forecast (double), and last week’s sales (int). The class must have two constructors (default and parameter), sets and gets for each data element, and a toString method. Only two data elements require error testing: product number must be greater than zero (0), and the smoothing factor must fall between 0.50 and 0.95. Errors must be reported via exceptions. The class must implement the Serializable interface. Step 2: Design and code a program to create and store objects of the five Sales items in an ArrayList and write the entire ArrayList to a binary file called “sales1.dat.” Use the table below to create the five Sales objects: Product Number Description Smoothing Factor Previous Forecast Sales 123 Heinz Catsup 0.8 45.4 55 244 Guilden's Mustard 0.85 23.4 28 303 Lipton Noodle Soup 0.9 9.0 6 445 Meow Mix Cat Food 0.7 25.7 43 501 Hershey's Chocolate Syrup 0.95 38.0 23 Step 3: Design and code the main (application) program that reads the sales1.dat file into an ArrayList. Close the input file as soon as it has been read. Step 4: For each sales record in the ArrayList, calculate the new forecast using the formula: nf = x(pf) + (1 – x)(s) where: nf = new forecast x = smoothing factor Final Project: Sales Forecasting pf = previous forecast s = sales The calculation should be placed in its own method and invoked (called) from main. Display the calculated results for each sales record as: 123 Heinz Catsup 0.8 45.4 55 – forecast: 47.6 Align the columns (decimal points should align), description should be left justified, all others right justified. Step 5: After testing the program thus far, create another method to update the fields in the ArrayList data. Set the previous forecast to the new forecast and set the sales value to zero (0). Step 6: Display all the sales records in the ArrayList using only the Sales class toString method. This should be done in its own method after the Step 5 update is completed. Step 7: Open another binary file as output, named “sales2.dat.” Write the now updated ArrayList to the new file. Close the file. Step 8: Reopen the sales2.dat file as input. Read the data into the ArrayList as was done in Step 3 above. Close the file. Then, using the method created in Step 6, display the sales records in the ArrayList. Step 9: Verify that the input from the sales2.dat file matches the output from the ArrayList in Step 6. Step 10: Fully document the main (application) program using the Javadoc format as has been demonstrated in the class

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

/**
*
* @author
*/
public class Program {

    /**
    * main function
    * @param args
    */
    public static void main(String[] args) {
       /**
         * Step 2: Design and code a program to create and store objects of the
         * five Sales items in an ArrayList and write the entire ArrayList to a
         * binary file called “sales1.dat.”
         */
       try {
            ArrayList<Sales> al = new ArrayList<>();
            al.add(new Sales(123, "Heinz Catsup", 0.8, 45.4, 55));
            al.add(new Sales(244, "Guilden's Mustard", 0.85, 23.4, 28));
            al.add(new Sales(303, "Lipton Noodle Soup", 0.9, 9.0, 6));
            al.add(new Sales(445, "Meow Mix Cat Food", 0.7, 25.7, 43));
            al.add(new Sales(501, "Hershey's Chocolate Syrup", 0.95, 38.0, 23));

            // write to file
            FileOutputStream fileOut
                   = new FileOutputStream("sales1.dat");
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(al);
            out.close();
            fileOut.close();
       } catch (Exception e) {
       }

       /**
         * Step 3: Design and code the main (application) program that reads the
         * sales1.dat file into an ArrayList. Close the input file as soon as it
         * has been read.
         */
       ArrayList<Sales> sales = null;
       try {
            // read from file
            FileInputStream fileIn = new FileInputStream("sales1.dat");
            ObjectInputStream in = new ObjectInputStream(fileIn);
            sales = (ArrayList<Sales>) in.readObject();
            in.close();
            fileIn.close();
       } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
            sales = new ArrayList<>();
       }...

By purchasing this solution you'll be able to access the following files:
SalesForecasting.zip.

$31.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats