Class ShippingMain

Object
ShippingMain

public class ShippingMain extends Object
This class uses helper methods and objects to read through the ShipmentFolder directory and construct a ShippingManifest object that is populated with Product objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Reads through list of File objects provided as parameter.
    static Product
    createProduct(Scanner fileScanner)
    This method loops through the fileScanner parameter provided, using the Scanner.hasNextLine() method and creates a Product object from the data being read.
    static void
    go(Scanner scnr, ShippingManifest shipManifest)
    This method prints the splash and reads from the provided Scanner object, using Scanner.nextLine().
    static void
    main(String[] args)
    This method creates an ArrayList of files from the provided "ShipmentFolder" directory, From that Arraylist a manifest is created and provided as a parameter, along with a Scanner object to our ShippingMain#go() method.
    static void
    This method prints the "splash" or "help" screen when someone uses the program.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ShippingMain

      public ShippingMain()
  • Method Details

    • createProduct

      public static Product createProduct(Scanner fileScanner)
      This method loops through the fileScanner parameter provided, using the Scanner.hasNextLine() method and creates a Product object from the data being read. Each file provided will have multiple lines specifying the NAME, SKU, PRICE, WEIGHT, DESTINATION, and QUANTITY.

      Each file will contain each of these fields, but lines will be provided in different orders, as they may be when provided by different suppliers. Such as:

      
       NAME: Berk's Salt Lamps
       SKU: 90435765
       PRICE: 12.99
       WEIGHT: 22.5
       DESTINATION: 83128
       QUANTITY: 22
       
      Each of these fields will exist in a given "Product.txt" file. Using if statements and the String.contains() method, determine if the newest line in the loop has one of these fields, and if it does, set the appropriate variable. For setting each variable you will need to use String.substring(). Integer.parseInt(int) and Double.parseDouble(double) will also come in handy for parsing and setting each variable.

      If the fields is not NAME, SKU, PRICE, WEIGHT, DESTINATION, or QUANTITY print an error, but still create the object.

      For your loop and reading a line from the Scanner object, the Scanner.hasNextLine() and Scanner.nextLine() methods will help!

      After reading through the entire file and setting the appropriate variables, create and return the new Product object.

      Parameters:
      fileScanner - Scanner set to a File object and ready to be read from.
      Returns:
      Product that is created from file contents.
    • createManifest

      public static ShippingManifest createManifest(ArrayList<File> fileList)
      Reads through list of File objects provided as parameter. For-each File within fileList, a File Scanner is created, and is called with createProduct(Scanner) to create a new product to be added to the shipManifest. the shipManifest is returned after each File object is used.
      Parameters:
      fileList - A List of File objects, which are files that represent their own product.
    • printSplash

      public static void printSplash()
      This method prints the "splash" or "help" screen when someone uses the program.
    • go

      public static void go(Scanner scnr, ShippingManifest shipManifest)
      This method prints the splash and reads from the provided Scanner object, using Scanner.nextLine(). While user input does not start with "X", continue to evaluate the user input. To evaluate the user input, if it begins with "D", "F", or "P" then perform the appropriate ShippingManifest method, ShippingManifest.distributeProducts(), ShippingManifest.forwardProducts(int), or ShippingManifest.printManifest(). If the provided command is not "X", "D", "F", or "P" just print a line saying unrecognized command.

      For the "F"orward case, the "F" command will provided as the letter F , a hyphen, and then the desired zipcode. Example: "F-81256", use the provided zipcode as the parameter for the forwardProducts(int) function.

      Some helpful methods to use may be Scanner.nextLine(), String.contains(), String.equals(), String.startsWith(), or String.substring()/ You may use none or all of these for your personal implementation.

      Parameters:
      scnr - Scanner object that is currently initialized to the Standard Input Stream.
      shipManifest - Populated ShippingManifest
    • main

      public static void main(String[] args)
      This method creates an ArrayList of files from the provided "ShipmentFolder" directory, From that Arraylist a manifest is created and provided as a parameter, along with a Scanner object to our ShippingMain#go() method.
      Parameters:
      args -