Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This project will allow you to write a program to get more practice with the stack and queue data structures, as well as more practice

This project will allow you to write a program to get more practice with the stack and queue data structures, as well as more practice with object-oriented ideas that we explored in the previous projects. In this assignment you will be writing a simulation of an order-fulfillment system for a company like Amazon.com. These companies take orders for products and ship them to customers based on what they have in inventory. For this assignment you will be performing a scaled-back version of this task you will write a program that will read an order from a text file, turn that order into a list of products, determine which products can be shipped now and which must be delayed until later, and then produce two reports one showing what will be shipped now, and one showing what portions of the order remain on hold for a later date. In the order-fulfillment system we are simulating, orders are fulfilled using either First-In, First-Out processing (for orders that can be fulfilled immediately). However, orders that must be delayed are prioritized in the reverse order they were made more recent orders should be fulfilled first and so follow Last-In, First-Out processing. Products that can be filled immediately should be reported in the order they appear in the file. Products that must be delayed should appear in the report in the reverse order that they appear in the input file. To perform this processing and receive full credit you must use queues and stacks to perform this processing as discussed below. For this program you will be writing a Product class to contain the data about each individual product in the database. You may write this class from scratch, or you may use the Product class you built in Lab 2 as a base for this lab. However, the Product class for this lab has some new requirements, so read below carefully and make sure you modify your class to implement these changes. Before beginning to code, think carefully about what you need to do to implement the requirements discussed below. Also consider how you will break the portions of this assignment that are not class-based down into smaller methods. Remember that monolithic solutions to this problem will lose points regardless of whether they produce the correct output or not.

Objectives

  • Practice with programming fundamentals
    • Review of various Java fundamentals (branching, loops, variables, methods, etc.)
    • Review of Java File I/O concepts
    • Practice with Java ArrayList concepts
    • Practice with object-oriented programming and design
    • Practice with Java interfaces
    • Practice with stack and queue data structures

Instructions

Create a new Project folder named StackQueue, then look at the instructions below.

Part I - The Product class

For this assignment you must design a class named SimpleProduct. This class must implement the Product interface given below. You must download this file and import it into your StackQueue source code folder before you can start to implement your own SimpleProduct class.

  • Product.java (Links to an external site.)

It is up to you how to represent the member variables of your SimpleProduct class, but it must implement all of the methods given in the interface. Note that your SimpleProduct class is similar to - but not exactly the same as - the Product class you created in a previous project. Feel free to copy that class and adjust it so that it implements the Product interface above for your submission for this assignment.

In addition, your SimpleProduct class must implement the following methods not provided in the interface, but are inherited from the Object class:

  • equals(Object obj) should return a true value if the name and type of the Product are the same.
  • toString() should return a string that contains the name of the product, the type of the product, the price and the quantity of the product as a comma-separated list enclosed in parentheses.

As you write this class, write a test program to go along with it. Test each method as you write it, as we have discussed in class. You will need to start with a skeleton of your SimpleProduct code that has each method in the interface written as a "stub" as seen in the Closed Lab code you have modified (i.e. code that does nothing but return a default value to allow the class to compile), and then you should modify your stub code one method at a time, testing each change you make. You will not need to submit this test program, but using it will make your code development much, much easier.

Part II - The Order Reporting Program

Write a well-structured program named OrderReporting.java that performs the following actions:

  1. Ask the user to enter the name of the file that contains the order database.
  2. Input the customer and product information from the file. See below for the file format information for the order fulfillment system - it contains more information than what you set up above. Customer information may be stored in any format you choose (though see below about creating a Customer class). Each individual product should be stored in its own Product object.
  3. Create two Collection objects a FIFO queue of orders to be fulfilled and a stack of orders to be delayed. Use the inStock attribute of each Product to determine which Collection they below to. Items that are in stock should be placed in the FIFO queue, while items that are out of stock should be pushed onto the stack.
  4. For the orders that can be fulfilled now, calculate the shipping cost and the sales tax. Sales tax information is in the customer block of the input data file (see below for the file format). Shipping cost is based on how much is ordered. Basic shipping is 15% of the total cost of the order. If there is at least $10 worth of product being shipped at a time, then the shipping cost is reduced to 5%. If there is at least $25 worth of product being shipped at a time, then the shipping cost is reduced to 0% (i.e. free shipping). Sales tax should be computed before adding in the cost of shipping, and shipping costs and sales tax should ONLY be calculated for orders actually being fulfilled, not for everything in the file.
  5. Output two well-formatted reports as outlined below. The first report is the report of orders to be fulfilled and should list the products that are able to be fulfilled now in FIFO order (i.e. in the order they appear in the file). The second report is the report of orders to be delayed, and should list the products that remain to be fulfilled in LIFO order (i.e. in the reverse of the order they appear in the file). Both reports should include a total dollar amount for the items in the order, and the fulfilled order report should include lines for shipping as well as sales tax.

The input file format for this order fulfillment system is:

customer last name customer first name customer street address customer city customer state customer zip customer sales tax product 1 name product 1 type product 1 price product 1 quantity product 1 instock?  product n name product n type product n price product n quantity product n instock? 

Note the inclusion of a block of customer information at the top of the file. After the customer information is finished, the product blocks continue just as the file format described in Part I above. A sample input file might look like this:

Fakename Bob 123 Fake Street Fake City FS 99999 0.07 The Shawshank Redemption DVD 19.95 1 true Dracula Book 4.95 1 false The Dark Knight DVD 19.95 1 true Lego Ultimate Building Set Toy 29.95 3 false The Girl With The Dragon Tattoo Book 14.95 1 true Iron Man DVD 19.95 1 false Under The Dome Book 19.95 1 true 

An example of the two reports that this file would generate is given below. Note that you will need to make use of Java's formatted output methods to get the report to output properly.

Enter database filename: lab4_input.txt Shipping To: Bob Fakename 123 Fake Street Fake City FS 99999 ------------------------------------------------------------------------------- 1 x The Shawshank Redemption (DVD) 19.95 1 x The Dark Knight (DVD) 19.95 1 x The Girl With The Dragon Tatto (Book) 14.95 1 x Under The Dome (Book) 19.95 --------------------------------------------------------------------------- Subtotal: 74.80 Sales Tax: (0.07) 5.24 Shipping: 0.00 --------------------------------------------------------------------------- Total: 80.04 ------------------------------------------------------------------------------- Orders Outstanding For: Bob Fakename 123 Fake Street Fake City FS 99999 ------------------------------------------------------------------------------- 1 x Iron Man (DVD) 19.95 3 x Lego Ultimate Building Set (Toy) 89.85 1 x Dracula (Book) 4.95 --------------------------------------------------------------------------- Outstanding Balance: 114.75 ------------------------------------------------------------------------------- 

Note that you can read a boolean value using the Scanner's nextBoolean() method. This works like nextDouble() or nextInt(). You can also use nextLine() to read the value as a String and then use Boolean.parseBoolean() to turn it into a boolean value - just like you would with Integer.parseInt(). See the Java API documentation for Boolean (Links to an external site.) and Integer (Links to an external site.) for more information.

product.java

/** * Product * * A simple interface for a possible family of Product * classes. * * @author Jeremy Morris * @version 20120928 */ import java.util.Scanner; public interface Product { /* * setName * @param name - new name for the product */ public void setName(String name); /* * getName * @return the name of the product */ public String getName(); /* * setType * @param type - the type of the product */ public void setType(String type); /* * getType * @return - the product type */ public String getType(); /* * setPrice * @param price - the price of the product */ public void setPrice(double price); /* * getPrice * @return the price of the product */ public double getPrice(); /* * setQuantity * @param quantity - the number of this product in inventory */ public void setQuantity(int quantity); /* * getQuantity * @return the number of this product in inventory */ public int getQuantity(); /* * setInStock * @param inStock - true if this product is in stock */ public void setInStock(boolean inStock); /* * getQuantity * @return true if this product is in stock */ public boolean getInStock(); /* * readNextProduct * @param inFile - a Scanner containing product entries * @return false if the product cannot be completely read, * true otherwise */ public boolean readNextProduct(Scanner inFile); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions