Product Recommender Algorithm
For this assignment, you will individually develop an Online Shop in Java that implements a Product Recommender Algorithm (PRA) that recommends related products based on your purchases. The PRA works by analysing transaction histories of Online Shop customers, observing the frequency products are purchased together. Products with high purchase frequencies with your current purchases are recommended to you.
A three-digit integer number represents each product offered by the Online Shop. For example, the numbers 123, 187, 199, 200, 865 represent unique types of products sold by the Online Shop (Note: each number represents a product code!). A customer’s purchase history is therefore a list of numbers. Here are the purchase histories from four different customers:
1.[187, 199, 200] 2.[187, 199, 123, 865] 3.[199, 123, 865] 4.[123, 199, 865, 187]
Suppose you purchase product 187. The PRA analyses each customer’s transaction histories. If 187 is found in the history then it keeps track of the other products that customer purchased, creating an observation map from products to frequencies:
123 -> 2 (e.g. 123 was purchased with 187 by customers 2. and 4.) 199 -> 3 (e.g. 199 was purchased with 187 by customers 1., 2. and 3.) 200 -> 1 (e.g. 200 was purchased with 187 by customers 1.) 865 -> 2 (e.g. 185 was purchased with 187 by customers 2. and 4.)
The PRA will then return products 123, 865 and 199 as recommendations since the observation frequency is greater than/equal to 2. For larger product databases and more customers, we might have recommendations based on higher frequencies.
Methodology and Marking Scheme
You will develop Java classes that implement the Online Shop. For full marks, your classes must adhere to correct OOP design principles. All source code must be documented according to Java doc standards.
You have been provided with an outline of 13 classes which contain the core functionalities of the Online Shop: OnlineShop, OnlineShopApp,
ProductNotFoundException, RecommenderSystem, Product, RecommendedItem, ProductDatabase, PurchaseHistory and 5 concrete classes as subclasses of Product class (these classes should be your own classes). The relationships between classes are described below using an UML Class Diagram (Figure 1). Complete the assignment by using the given UML class diagram and following the below steps to develop the 13 classes with the provided instance variables and methods using appropriate access modifiers (as shown in the diagram), taking the time to test your methods as you progress.
Note1: You need to provide attributes and methods that are listed in UML diagram even those which are not defined in the step sections. Some of them are clear and that’s why did not mention in steps. (Please follow method signatures in UML diagram)
Note2: You can develop your own methods if you think it is required to have more modular and OO code!
Note3: The OnlineShopApp class in UML has not specific attribute and method as you need to write your own code and define several methods to make good online shop application. Try to make modular code. Rather having a long method doing lots of functionalities, try to have more methods that each can do specific function.
Figure 2: UML Diagram of Online Shop Application with Recommender System
OnlineShop - productDB: ProductDatabase - cart: ArrayList OnlineShopApp <> - recommender: RecommenderSystem your own code for attributes PaymentSystem + OnlineShop(ProductDatabase, ArrayList) your own methods to + getRecommendedProducts(): ArrayList + addToCart(Product): boolean support online shop + amountOwing(): Double funtionalities including main + getProductListing(): ArrayList method! + completeTransaction() + getShoppingCart(): ArrayList + amountOwing(): Double + completeTransaction(): void
- purchaseHistories: ArrayList - productDB: ProductDatabase - recommend: ArrayList + RecommenderSystem(ArrayList, ProductDatabase) + getProductFreq(Product): int + updateProductFreq(Product): void <> + productRecommenderAlgorithm(ArrayList, int): ArrayList Comparable + compareTo(E): int RecommendedItem <> Product - product: Product - price: Double - freq: int + RecomendedItem(Product, int) - code: Integer ProductDatabase + Product (Integer, Double) + getProduct(): Product - database: ArrayList + setProduct(Product) + getPrice(): Double + getFreq(): int + setPrice(Double) + ProductDatabase() + setFreq(int) + getCode(): Integer + put(Product) + setCode(Integer) + get(Integer): Product + compareTo(Product) + getProducts(): ArrayList + toString(): String PurchaseHistory - purchases: ArrayList + PurchaseHistory(ArrayList) + getPurchases(): ArrayList + toString(): String Subclasses of Product (5 classes) Create your own classes as subclasses of Product
NOTE: do not create the classes related to the products mentioned in sample output!
Design an abstract Product class that:
•stores a product’s code as an Integer and its price.
•implements the Comparable interface
Extend the Product class by at least five concrete classes. Each subclass must have
•two or more attributes,
•a constructor with input parameters for all attributes, including inherited attributes
•a toString method
The product database and purchase history classes
Design ProductDatabase class. Products are stored in this class, which comprises:
•an ArrayList collection, storing Product objects.
•A constructor initializes the ArrayList of Products.
•A put method that provided the functionality for adding products to the database.
•A get method that returns a product from the database based on product code received as input parameter.
•A getProducts method that returns the unique (not repeated) products stored in the database as an ArrayList.
Note: You do not need to remove products from the database.
Design PurchaseHistory class. This class models the purchase history of a customer. It contains an ArrayList of product objects, supplied by the constructor. The class has a single get method for the ArrayList but no set or other updating methods.
Payment System Functionality
The PaymentSystem is modelled as an interface, comprising two methods: 1.public Double amountOwing();
2.public void completeTransaction();
The payment system is implemented by the Online Shop, which provides method bodies to compute the amount the customer owes. The complete transaction method simply clears the shopping cart.
Design a RecommendedItem class that:
•stores a product’s object and its frequencies in a purchase histories of an online shop (i.e. frequencies mean number of times an object purchased by customers in the online shop).
The Recommender System
The RecommenderSystem class has
•instance variables for the product database
•an ArrayList containing customer purchases history objects.
•The constructor initializes both instance variables.
•a single method with the signature
public ArrayList prAlgorithm(ArrayList cart, int freq)
with the customer’s shopping cart and a frequency as input, returning a list of recommended products (Hint: use objects of RecommendedItem. You may need to create ArrayList of RecommendedItem objects and make that ArrayList as an attribute of class to be accessible via the other methods in the class). Consider the following input:
Method Invocation Output praAlgorithm(,2) [123,199,865] praAlgorithm(,3)  praAlgorithm(,2)  praAlgorithm(,1) [199,187] praAlgorithm(,2) [199,865,187] praAlgorithm(,3) [199,865]
Now look at the example and try to calculate the output yourself. Use this process to devise an algorithm to compute the recommendations.
The OnlineShop is modelled by a Java class that
•contains a ProductDatabase and a RecommenderSystem.
•maintains a shopping cart that contains products the customer has selected to purchase.
•implements a PaymentSystem oto compute the amount owing and, ocompleting the customer’s transaction (which also clears the cart).
Online Shop Application (Program Interaction)
The Online Shop Application provides interaction between the customer and an Online Shop object. It provides menu interactions for
1)Adding a product to the cart, which lists all products in the database, from which the customer can select from 2)Viewing the products in the shopping cart
3)Finalize purchases, which uses a payment system to compute the total amount owing and to process the transaction. When the payment is completed, the customer is given product suggestions based on what they have purchased.
All product lists displayed in 1) to 4) must be sorted by price, in ascending order.
How to get started
The first step to getting started on the assignment is creating the Product abstract class and deciding how the class should be extended using at least 5 subclasses. Think of interesting examples of products to sell. They must be different from the ones shown in the console sample provided; otherwise you will get zero marks for that portion of the assignment. The point here is to think about developing your own classes.
Once you have finished this, you can instantiate products with product codes 123, 187, 199, 200 and 865 (from the example) and generate a sample product database. I suggest that you write a static method in your Online Shop Application class, which initialises and returns a product database object with these five products using the following signature:
public static ProductDatabase generateSampleDatabase()
The text file purchase-history.txt is provided to you with this assignment. It contains the purchase histories of the four customers shown in the example.
In your Online Store Application class, write a static method which reads this text file, and has the following signature:
public static ArrayList readPurchaseHistoryData(ProductDatabase pb,String filename) throws ProductNotFoundException,IOException,NumberFormatException
This method reads the text file and throws the following exceptions: 1)IOException, thrown if the file cannot be opened/read 2)NumberFormatException, thrown if integer parsing fails
3)ProductNotFoundException, your own exception, which is thrown if a product code does not appear in the database.
You also need to write a method called writePurchaseHistoryData to write the new purchase history from console into the purchase-history.txt. you need to keep the history data and add to the existing file. The method writes to the text file and throws the IOException, if the file cannot be opened/written.
Your main method should try to read/write the purchase history data, handling exceptions in an appropriate way (potentially by terminating execution with a meaningful message, but not by an uncaught exception).
Note: Your application should also elegantly handle exceptions occurring from bad user input.
Bonus Part (additional 10 marks for assignments)
If you are interested, develop a GUI for this application. You need to have your own design for GUI functionalities. Based on your design you will get the bonus mark which will be added to your assignment mark.
Marking Scheme Weight: 100 ≥ x ≥ 80% 80 > x ≥ 65% 65 > x ≥ 50% 50 > x ≥ 0% Grade A Grade B Grade C Grade D Criteria: Range Range Range Range Inconsistent use of OOP paradigm consistently used Inconsistent use of OOP OOP paradigm or paradigm. Correct poor product Product and for implementation of all Absent product classes or 20% implementation of subclasses. Correct subclasses product classes. Meaningful code does not compile product class implementation of subclasses are defined. functionality product class functionality Inconsistent use of Product OOPS paradigm consistently Inconsistent use of OOP OOP paradigm. paradigm. Correct use of Incorrect use of Absent product database Database & used. Good use of collections in 10% collections with correct collections but with or purchase history or Purchase both classes, with correct functionality mostly correct code does not compile History functionality implementation implementation functionality implementation OOP paradigm consistently used Inconsistent use of OOP Some basic Absent functionality of paradigm but correct functionality of Online Shop 10% for implementation of all Online Online Shop or code does implementation of Online Online Shop/poor Shop functionality. not compile. Shop functionality usage of collections OOP paradigm consistently Inconsistent use of OOP Incorrect paradigm. Correct Absent functionality of the Recommender used. Correct implementation implementation of 10% implementation of recommender system or System of algorithm with good choice of algorithm/poor algorithm with good code does not compile collections. choice of collections choice of collections. Online Store App The object-oriented program is The object-oriented The object-oriented Runtime unique, purposeful and provides program is unique, program features an Demonstration: an elegant implementation of purposeful. Reasonable incomplete Absent functionality of the Online Shop Application. implementation of the demonstration of the Online Shop Application or -Uniqueness 20% Online Shop Application. Online Shop code does not run after -Purpose Program is interactive. Program is interactive. Application compiling -Context All exceptions are handled. Some errors reading text -Interactive Purchase history text file is read file or generating product Program is not Sample product database databases. interactive generated. Code Quality: Whitespace is comprehensively Whitespace is Whitespace is -Whitespace comprehensively comprehensively consistent. All naming is sensible Whitespace is inconsistent -Naming consistent. Majority of consistent. Code has 15% and meaningful. Code reuse is and hence code is difficult -Reuse naming is sensible. Code some modularity. present. Code is modular. Code to read. -Modularity is modular. Code is Code has some is well encapsulated. -Encapsulation encapsulated. encapsulation. Documentation Entire codebase has Majority of the codebase Some Javadoc Standards: features Javadoc comments present. comprehensive Javadoc commenting. Majority of Some algorithms are No Javadoc comments -Algorithms 15% commenting. Algorithms are algorithms are commented. present. Commented well commented. commented. -Javadoc
1. Your classes must have commenting of the form:
*Comment describing the class.
*@author yourname studentnumber **/
2. All methods must be commented with appropriate Javadocs metatags. For example:
*A comment to describe the method *@param a first parameter description
*@param b second parameter description *@return a description of the returned result *@author Jamal studentnumber **/
Remember, it is unacceptable to hand in any code which has previously been submitted for assessment (for any paper, including Programming 2) or available online, and all work submitted must be unique and your own! Submission Instructions
Submit the following documents as an archive .zip file of your documents on Blackboard before the deadline:
•Your full java project for assignment.
•Sample console output demonstrating your program in use (.txt file)
Zip structure and file naming requirements. Please ensure your submission matches the following: lastname-firstname-studentid.zip
Project folder (can be find in your workspace)
Replace the underlined text with your personal details.
An extension will only be considered with a Special Consideration Form approved by the School Registrar.
You will receive your marked assignment via Blackboard. Please look over your entire assignment to make sure that it has been marked correctly. If you have any concerns, you must raise them with the lecturer. You have one week to raise any concerns regarding your mark. After that time, your mark cannot be changed.
Do not go to the lecturer because you do not like your mark. Only go if you feel something has been marked incorrectly.