Computer Science

HW#02-W4Mon-OnlineBookstore-Rev3.docx Page 1 of 3

TCSS 305A Programming Practicum (Autumn 2019)

Programming Assignment #2 – Online Bookstore Application (Interface Extensions and Unit Tests)

Due Date:

Submit Part I (Requirements Analysis & Planning) by 11:00 am on Fri, Oct 25th, 2019 Submit Part II (Design, Implementation & Testing) by 11:00 am on Mon, Oct 28th, 2019

Rev.3 on Mon, Oct 21st, 2019 / Will be posted on Oct 22nd. I. Problem Definition: In this assignment,

(1) you will refactor and improve your online bookstore application code that you submitted in Programming Assignment #01,

(2) add new methods to it, and (3) write unit tests to test it using the JUnit 5 unit testing framework.

II. Implementation Guidelines: Task 1) Review your past implementation carefully and correct/revise/improve your codes. This process is called “code refactoring.” Please mark each improvement with a tag (i.e., such as “// Refactoring 01) on your code and explain the changes in the related essay question by referring to the improvement(s) you made by their tag name. Task 2) Override the following default methods of the java.lang.Object in the user-defined LineItem (or actually ItemOrderin the provided codes) class following the recommended practices in the textbooks, Core Java (Chapter 5) and Effective Java (Chapter 3):

Method Description String toString()

returns a String representation of this object.

boolean equals(Object)

returns true if the specified object in the argument is equivalent to this object, and false otherwise.

int hashCode()

returns an integer hash code for this object. This method must override java.lang.Object.hashCode() and be consistent with equals().

TCSS 305A (Autumn 2019) – Programming Assignment #1

Page 2 of 3

Task 3) Override the following default methods of the java.lang.Object in the user-defined Cart class following the recommended practices in the textbooks, Core Java (Chapter 5) and Effective Java (Chapter 3):

Method Description String toString()

returns a String representation of this object.

boolean equals(Object)

returns true if the specified object in the argument is equivalent to this object, and false otherwise.

int hashCode()

returns an integer hash code for this object. This method must override java.lang.Object.hashCode() and be consistent with equals().

Task 4) When a class implements the Comparable<T> interface, it is said that this imposes a total ordering – refers to the natural ordering of the class – on the objects of the class.

Revise the implementation of the Item class to implement the Comparable<T> interface and add an appropriate CompareTo method to compare items by their name which is the natural ordering of the class. This will allow the use of built-in collection sort methods to order any collection of items by name.

Task 5) Assume that we would also like to be able to use collection sort methods to order a collection of Item objects by their item price. Add another method called orderByPrice to compare items by their price.

Revise the implementation of the Item class Implement the Comparator<T> interface and add an appropriate Compare method to compare items by their name. This will allow the use of built-in collection sort methods to order any collection of items by price.

Task 6) For the calculateTotal method of the Cart class, write required JUnit 5 test cases to make sure that the following two cases displayed on the screen snapshots below have been correctly handled.

Task 7) For each of the new methods you added to the code in Tasks 2-5, write sufficient number of distinct JUnit 5 test cases to make sure that all possible cases have been correctly handled.

TCSS 305A (Autumn 2019) – Programming Assignment #1

Page 3 of 3

III. Stylistic Guidelines: Part of your program’s score will come from its “external correctness” and “internal correctness” as in previous programming assignments. It is therefore to your advantage to check your programs with the plug-in tools before you submit it and get rid of all (or most important) warnings.

The program style will also affect your score, therefore be careful about the style as in previous assignments. The same guidelines with the previous ones are valid for this assignment. Your assignment will lose points if it does not follow the guidelines properly.

Note that, you can find the detailed instructions for some of the following items in the hw0-project description and in the Guidelines posted under the Canvas Files > Guidelines folder.

IV. Submission: • Submit your source codes by committing them onto SVN. A README file located in the main folder should explain

to anyone other than you the required details about how to load and run your code, organization of your source files, required settings (if any), etc. so that we can load and evaluate your codes on our machines.

• Submit your text answers to the essay questions via Canvas using the given textboxes after the assignment. You may also want to enrich your submission by inserting links, uploading images (such as your design sketches, snapshot of sample codes, etc.) in some cases where it is not easy or convenient to type in the answers.

Order now and get 10% discount on all orders above $50 now!!The professional are ready and willing handle your assignment.

ORDER NOW »»