Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Inheritance and Interfaces Overview In this homework, you will implement a syste

ID: 3673701 • Letter: I

Question

Inheritance and Interfaces

Overview

In this homework, you will implement a system that reads in an inventory file, prints the

inventory to the console, and ships items.

Business Rules

There are two types of items tracked in the system: food items and household (durable) items.

Food Items: Food items are perishable, and a perishable item has a limited shelf life. The item must be removed from the shelf when it expires. The expiration date is simply

expiration date = date placed in inventory + shelf life in days

Household Items: Household items have unlimited shelf life, so they do not have an expiration date. They do have (sometimes substantial) weight. The shipping cost is

$10.00 / pound. If the item is shipped on a weekend day, the shipping cost should be increased by $20.00.

–      Example: a 20 pound item shipped on Saturday would have a shipping cost of

$220.00.

Program Design

Input

The program will take as input a file formatted as follows:

food,banana,5 food,bread,10 household,toaster,5 household,washer,200

The first element in a line is the type of item: food or household good. If the item is a food item, the second element is the name, the third is the shelf life in days. If the item is a household good, the second element is the name and the third is the shipping weight in pounds.

You will create an input file with the data above called "input.txt". When you load the file you should not use a full path.

Program Flow

The following pseudocode shows the required flow of the program.

Begin

for each line in inventory file do determine inventory type

based on type, create object to hold data (FoodItem or Household Item)

populate item with appropriate data (weight, etc) store in inventory list

end

for each item in inventory list do print item

end

request shipping date from user

for each household item in inventory do

determine shipping cost based on shipping date print shipping cost

end

End

Output

The output of the program for the input above would be

Item banana

-­?-­? Shelf Life: 5

-­?-­? Remove from Shelf: Fri Oct 10 19:37:29 CDT 2016 Item bread

-­?-­? Shelf Life: 10

-­?-­? Remove from Shelf: Wed Oct 15 19:37:29 CDT 2016 Item toaster

-­?-­? Weight: 5 Item washer

-­?-­? Weight: 200

Please enter a shipping date: March 16, 2016

Toaster will be shipped on March 16, 2016. Shipping cost is $70.00. Washer will be shipped on March 16, 2016. Shipping cost is $2020.00.

NOTE: The remove from shelf dates are based on the date the program is run. They will not be the same as those shown above.

UML and Javadoc

as a zipped directory and on the web at http://162.243.207.40/.

Approach

Start by creating all the classes and interfaces and their methods and properties without worrying about what the methods do. When you have this code compiling, go back and implement the methods. For each class and method, read the relavent portion of the Javadoc and look at where it fits in the overall flow of the program (see the pseudocode).

Inventoryltem T_name Perishable getShelfLife0 Shippable calculateShippingCost(String) doublegetName0 String String String int n getExpiredDate0 Date toString() Fooditem shelfLife 1 stockedDate C Householdltem 1 weight m calculateShippingCost(St m isWeekend(Date) oolean int Date Date int Date String int .unusableDate mgetShelfLife0 toString() String m getExpiredDate0 m toString0 GInventoryManager O inventory main(String[]) shipAllHouseholdItems(String) load Inventory(String) print! nventory() ArrayList void void void void

Explanation / Answer

Based on the given pseudocode it is implemented as follows

import java.lang.Object

public abstract class InventoryItem

extends java.lang.Object

public class FoodItem

extends InventoryItem

implements Perishable

public class HouseholdItem

extends InventoryItem

implements Shippable

public HouseholdItem(java.lang.String name,int weight);

public double calculateShippingCost(java.lang.String shipDateString)

throws java.text.ParseException;

public java.lang.String toString();

public FoodItem(java.lang.String name,int shelfLife);

public int getShelfLife();

public java.util.Date getExpiredDate();

public java.lang.String toString();

{

protected final java.lang.String _name;

public java.lang.String getName();

public java.lang.String toString();

public java.lang.String getName()

{

System.out.println("returns the name of the object");

}

public java.lang.String toString()

{

system.out.println("returns in the form of string");

}

}

public class InventoryManager

extends java.lang.Object

public InventoryManager()

{

public static void main(java.lang.String[] args);

public void shipAllHouseholdItems(java.lang.String dateString);

public void printInventory();

}

public static void main(java.lang.String[] args)

{

system.out.println("loads the inventory file with shipping date :");

}

public void shipAllHouseholdItems(java.lang.String dateString)

{

system.out.println("calculates the shippingcost on each of the items and the result is:");

}

public void printInventory()

{

system.out.println("the inventory consists of:");

}

}

and for the food item and house hold items it follows the same procedure