Description

Part 1

Items that people can purchase must implement the Item interface:

/*
* Represents an item purchased at an e-commerce web site. An item has
* associated with it an item id (the unique stock number for this item),
* an item name (a string name for the item), a quantity (the number of
* units of the item) and a unit price (the price of each unit of the
* item.) Note that implementations of this interface should use
* their constructors to set the initial values of these attributes.
*/
public interface Item {
/*
* Returns the number of units of this item.
* @return Number of units of this item.
*/
public int getQuantity ();

/*
* Returns the stock number for this item.
* @return The stock number (unique id) for this item.
*/
public String getItemId ();

/*
* Returns the (non-unique) string name of this item.
* @return String name of this item
*/
public String getItemName ();

/*
* Returns the unit price of this item (before tax.) E.g., if there
* are three units of the item, and each costs $2.99, this method
* will return 2.99.
* @return Unit price of item
*/
public float getUnitPrice ();

/*
* Returns the price of this item. This is simply the product of the
* (unit cost) * (number of units)
* with applicable taxes added.
* @return Price of this item
*/
public float getTotalPrice ();

/*
* Returns this item in string form suitable for displaying.
* @return Displayable form of item.
*/
public String toString();
}

In Ontario, the taxes to be added to items include the provincial sales tax (PST) of 8%, together with the federal sales tax (GST) of 7%. In Alberta, there is no provincial sales tax, so prices include only the GST. Provide two implementations of the Item interface, one for Ontario and one for Alberta. Provide a class diagram showing these classes and their attributes. Hint: you may implement a common superclass for items which your Ontario and Alberta classes extend. You may not modify the Item interface.

Part 2

Using the abstract factory design pattern, create an ItemFactory interface, and implementations of this interface for the Ontario and Alberta item classes. Provide a class diagram showing how the abstract factory pattern was applied. This interface is as follows:

public interface ItemFactory {
/*
* Creates an Item with the given stock id, name and quantity.
*/
public Item createItem (String id, String name, int quantity, float unitPrice);
}

Part 3

A shopping basket class should implement the following interface:

import java.util.Enumeration;
public interface ShoppingBasket {
/*
* Adds an item into the shopping basket. If the item
* is already in the basket, the number of units of this item
* are added to the quantity of the existing item.
* @param newItem The item to be added.
*/
public void addItem (Item newItem);

/*
* Removes the given item from the shopping basket. The
* number of units in deletedItem are removed from the
* basket. E.g., if there are 10 units of the item in the
* basket, and we remove 3 units of the item, 7 units will
* remain.
*/
public void removeItem (Item deletedItem);

/*
* Returns an enumeration allowing the shopping list to be
* traversed.
*/
public Enumeration elements ();

/*
* Returns a version of the shopping basket in string form
* suitable for displaying.
*/
public String toString ();
}

Provide an implementation of this interface. Your implementation should use the object adapter design pattern, based on Java’s Hashtable class. Provide a class diagram showing how the object adapter pattern was applied. In case of ambiguity in the description of the Shopping Basket interface above, include a note in your report explaining the ambiguity and how you resolved it.

Hints:

  • Look at the documentation for the Enumeration interface and the Hashtable class.
  • You can use the item id as a hash key.
  • Note that the Hashtable class already implements a method that returns an enumeration.
  • In order to change the quantity of an item, you actually have to remove that item from the Hashtable and add a new item with the correct quantity. Use your item factory from part 2 to create the new item. You will need to pass this factory to the ShoppingBasket in its constructor.

For more information about this assignment visit the below reference: http://research.cs.queensu.ca/~elec372/as3.htmlPart 1

Items that people can purchase must implement the Item interface:

/*
* Represents an item purchased at an e-commerce web site. An item has
* associated with it an item id (the unique stock number for this item),
* an item name (a string name for the item), a quantity (the number of
* units of the item) and a unit price (the price of each unit of the
* item.) Note that implementations of this interface should use
* their constructors to set the initial values of these attributes.
*/
public interface Item {
/*
* Returns the number of units of this item.
* @return Number of units of this item.
*/
public int getQuantity ();

/*
* Returns the stock number for this item.
* @return The stock number (unique id) for this item.
*/
public String getItemId ();

/*
* Returns the (non-unique) string name of this item.
* @return String name of this item
*/
public String getItemName ();

/*
* Returns the unit price of this item (before tax.) E.g., if there
* are three units of the item, and each costs $2.99, this method
* will return 2.99.
* @return Unit price of item
*/
public float getUnitPrice ();

/*
* Returns the price of this item. This is simply the product of the
* (unit cost) * (number of units)
* with applicable taxes added.
* @return Price of this item
*/
public float getTotalPrice ();

/*
* Returns this item in string form suitable for displaying.
* @return Displayable form of item.
*/
public String toString();
}

In Ontario, the taxes to be added to items include the provincial sales tax (PST) of 8%, together with the federal sales tax (GST) of 7%. In Alberta, there is no provincial sales tax, so prices include only the GST. Provide two implementations of the Item interface, one for Ontario and one for Alberta. Provide a class diagram showing these classes and their attributes. Hint: you may implement a common superclass for items which your Ontario and Alberta classes extend. You may not modify the Item interface.

Part 2

Using the abstract factory design pattern, create an ItemFactory interface, and implementations of this interface for the Ontario and Alberta item classes. Provide a class diagram showing how the abstract factory pattern was applied. This interface is as follows:

public interface ItemFactory {
/*
* Creates an Item with the given stock id, name and quantity.
*/
public Item createItem (String id, String name, int quantity, float unitPrice);
}

Part 3

A shopping basket class should implement the following interface:

import java.util.Enumeration;
public interface ShoppingBasket {
/*
* Adds an item into the shopping basket. If the item
* is already in the basket, the number of units of this item
* are added to the quantity of the existing item.
* @param newItem The item to be added.
*/
public void addItem (Item newItem);

/*
* Removes the given item from the shopping basket. The
* number of units in deletedItem are removed from the
* basket. E.g., if there are 10 units of the item in the
* basket, and we remove 3 units of the item, 7 units will
* remain.
*/
public void removeItem (Item deletedItem);

/*
* Returns an enumeration allowing the shopping list to be
* traversed.
*/
public Enumeration elements ();

/*
* Returns a version of the shopping basket in string form
* suitable for displaying.
*/
public String toString ();
}

Provide an implementation of this interface. Your implementation should use the object adapter design pattern, based on Java’s Hashtable class. Provide a class diagram showing how the object adapter pattern was applied. In case of ambiguity in the description of the Shopping Basket interface above, include a note in your report explaining the ambiguity and how you resolved it.

Hints:

  • Look at the documentation for the Enumeration interface and the Hashtable class.
  • You can use the item id as a hash key.
  • Note that the Hashtable class already implements a method that returns an enumeration.
  • In order to change the quantity of an item, you actually have to remove that item from the Hashtable and add a new item with the correct quantity. Use your item factory from part 2 to create the new item. You will need to pass this factory to the ShoppingBasket in its constructor.

For more information about this assignment visit the below reference: http://research.cs.queensu.ca/~elec372/as3.html