Class ShippingMain
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ShippingManifestcreateManifest(ArrayList<File> fileList) Reads through list of File objects provided as parameter.static ProductcreateProduct(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 voidgo(Scanner scnr, ShippingManifest shipManifest) This method prints the splash and reads from the provided Scanner object, using Scanner.nextLine().static voidThis 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 ourShippingMain#go()method.static voidThis method prints the "splash" or "help" screen when someone uses the program.
-
Constructor Details
-
ShippingMain
public ShippingMain()
-
-
Method Details
-
createProduct
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:
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.NAME: Berk's Salt Lamps SKU: 90435765 PRICE: 12.99 WEIGHT: 22.5 DESTINATION: 83128 QUANTITY: 22If 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
Reads through list of File objects provided as parameter. For-each File within fileList, a File Scanner is created, and is called withcreateProduct(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
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), orShippingManifest.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
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 ourShippingMain#go()method.- Parameters:
args-
-