+1 (315) 557-6473 

Create a Program to Implement Item Shipping in Java Assignment Solution.


Write a program to implement item shipping in java language.

Requirements and Specifications

This Programming Project allows you to demonstrate your basic knowledge of Object-Oriented Programming and the use of text files for input and output. You will use information read from one text file to create instances of a class named InventoryItem. Next, you will read information from a second text file to update information about the quantities of these inventory items. Finally, you will use the information in the collection of InventoryItem objects you created and updated to prepare a report that is written to an output file showing the quantity and value of each inventory item as well as the overall value of all inventory items. Start by designing a class called InventoryItem. This class contains the following private fields:
sku, a unique stock keeping number used to identify each item. (int)
description, the text description of the item. (String)
quantity, the number of items in the inventory. (int)
unitCost, the value of a single unit in dollars and cents. (double)
The InventoryItem class has the following methods:
A constructor that can be used to create an instance of the InventoryItem class. All the fields must be specified as arguments. This method guards against initializing the quantity to a negative number by setting the quantity to zero if it was less than zero.
A receiveItems method that accepts as an argument the quantity of the item to be added to any existing quantity. Guard against receiving a quantity that is less than or equal to zero. Instead, display a warning message.
A shipItems method that attempts to reduce the quantity of the item. This method must not reduce the quantity of an item below zero. If an argument is passed to this method that would reduce the quantity below zero, a warning message will be displayed instead of changing the quantity.
A setQuantity method that accepts as an argument a new quantity value for the inventory item. This method must also guard against setting the quantity to a value that is less than zero.
A getSku method that returns the value of the sku field.
A getDescription method that returns the value of the description.
A getQuantity method that returns the value of the quantity.
A getUnitCost method that returns the value of the unitCost.
A toString method that returns a String describing the dollar value of the inventory item.
Place the class definition for InventoryItem in a separate file called “InventoryItem.java”.
Design your solution so that it can handle up to a maximum of 60 inventory items.
Your Java program will read and process two input text files and create a single output text file in addition to displaying limited screen output. Your program will prompt the user for the name of the file containing the item definitions and use a portion of the contents of this file to initially create and define the inventory item objects.
The “items.txt” text file contains the definition of several inventory items. Each record in this file contains the following information in this order:
The fields in this file are comma-separated. That is, each field is separated from the next field by a comma. Example records for this file look like this:
12345,Ballpeen Hammer,25,18.75
56789,Phillips Screwdriver,120,10.95
24680,Claw Hammer,35,15.98
13579,Box Wrench,48,20.35
Although this file contains definitions for all the items in the company’s inventory, your program will only process the subset of records where the value of the sku is in the range from 20010 to 89990.
After creating instances of the InventoryItem class, display a single line of output reporting how many inventory items were created. Your program will then prompt the user for the name of the file containing the inventory transactions. This text file contains transaction activity that will potentially change the quantities of individual inventory items. These are the codes used for the possible transactions:
“D” Define the quantity of an inventory item
“R” Receive an additional quantity of an inventory item
“S” Ship a quantity of an inventory item
Records within the “activity.txt” text file contain the following commaseparated fields:
transaction code (“D”, “R”, or “S”)
Example records for the “activity.txt” file look like this:
Process only records in the “activity.txt” file that effect items you defined earlier (using the “items.txt” file) AND contain a valid transaction code (“D”, “R”, or “S”). Keep track of the total number of records processed as well as the number of records that were skipped either because they did not have a valid transaction code, or they dealt with an inventory item that was not created earlier (using the “items.txt” file).
After processing the entries in the “activity.txt” file your program can now display two items as output. Display the total number of records processed as well as the number of records skipped for any reason.
The final step in this programming project is to calculate and display the inventory value of each item as well as the grand total of all the inventory items. This information will be written to an output text file named “Report.txt”. The first line of your inventory report will contain your full name and a made-up name for the company such as “The Albatross Company, Ltd.” Do not use “The Albatross Company, Ltd.” in your report. It is just an example. The second line in your inventory report will contain the phrase, “Prepared on:” followed by the current date and time. (I know, go look it up on the Internet.) The third line will be blank. The fourth line in your report is where the heading information begins. Your inventory report will look like this:
Joe E. Bagadonutz for the Albatross Company, Ltd. Prepared On: Thursday, May 31, 2018 at 05:36:15
NumberDescriptionQuantityUnit Price Value
56789Phillips Screwdriver12010.951,314.00
24680Claw Hammer5515.98878.89
28967Hex Wrench7019.981,398.60
30127 1/4 inch Drill1634.89558.24
44021 3 inch Trowel3810.74408.12
290371 inch Paintbrush732.95215.35

Total $4,773.21
Once the inventory report is complete, display the overall dollar worth of all the inventory items as a line of output.
Except for discovering how to add the current date and time to your report, your textbook contains more than enough information and examples to allow you to complete the java assignment. This project is not about discovering a solution on the Internet and submitting all or part of that solution as your own work.
Your assignment program will display something like the following to the screen:
Attempt to create Inventory Item 44392 with a negative quantity. The quantity field for item 44392 has been set to zero. 18 inventory items have been created.
Bad Transaction code: X in record 7 The quantity you attempted to ship for item 24680 was 111 The current quantity of item 24680 is 65 The quantity you attempted to define for item 31209 was -5 This value must be greater than or equal to zero (0). 21 records processed; 1 records skipped. 14 inventory item quantity transactions. Total Inventory Value is $16,662.36
Source Code
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class App
public static void main(String[] args) throws Exception
// Create Scanner
Scanner sc = new Scanner(System.in);
// create list to store inventory items
List inventory = new ArrayList();
// ask for items file
String items_file;
System.out.print("Enter name of file containing definition of items: ");
items_file = sc.nextLine();
// Attemp to read
int sku;
String description;
int quantity;
double unitCost;
BufferedReader reader = new BufferedReader(new FileReader(items_file));
String line;
// Read each line in the file
while((line = reader.readLine()) != null)
// Split the line by comma
String[] data = line.split(",");
sku = Integer.valueOf(data[0]);
description = data[1];
quantity = Integer.valueOf(data[2]);
unitCost = Double.valueOf(data[3]);
// check that sku is between 20010 and 89990
if(sku >= 20010 && sku <= 89990)
InventoryItem item = new InventoryItem(sku, description, quantity, unitCost);
// close file
// Display number of InventoryItems read
System.out.println("A total of " + inventory.size() + " items read.");
// Now, open transactions file
String transactions_file;
System.out.print("Enter name of the file containing transactions: ");
transactions_file = sc.nextLine();
String code;
int processed = 0;
int transactions = 0;
reader = new BufferedReader(new FileReader(transactions_file));
// Read each line in the file
while((line = reader.readLine()) != null)
String[] data = line.split(",");
code = data[0];
sku = Integer.valueOf(data[1]);
quantity = Integer.valueOf(data[2]);
// apply transaction to file with SKU
for(InventoryItem item: inventory)
if(item.getSku() == sku)
if(code == "D")
else if(code == "R")
else if(code == "S")
// Print info about number of transactions processed and skipped
System.out.println("A total of " + processed + " transactions were processed and " + (transactions-processed) + " were skipped.");
// close reader
// generate report
String HEADER = "YOUR_NAME_HERE for the Awesome Depot Company, Ltd. Prepared On: ";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
HEADER += dtf.format(now);
BufferedWriter writer = new BufferedWriter(new FileWriter("Report.txt"));
writer.write(HEADER + "\n");
writer.write(String.format("%-10s\n", "I N V E N T O R Y R E P O R T"));
writer.write(String.format("%-10s\n", "Intentory Item"));
writer.write(String.format("%-10s %-10s %25s %10s %20s\n", "Number", "Description", "Quantity", "Unit Price", "Value"));
writer.write(String.format("%-10s %-10s %25s %10s %20s\n", "------", "-----------", "--------", "----------", "-----"));
double total = 0.0;
for(InventoryItem item: inventory)
writer.write(String.format("%-10d %-10s %25d %10.2f %20.2f\n", item.getSku(), item.getDescription(), item.getQuantity(), item.getUnitCost(), item.getTotalCost()));
total += item.getTotalCost();
writer.write(String.format("%60s $%10.2f\n", "Total", total));
System.out.printf("The total of all the items is $%.2f\n", total);