Recent Question/Assignment

Assignment CSC 1401
Goals and Topics
The assignment problem is straightforward. All necessary details have been supplied. The solution of the problem will use the programming concepts and strategies covered in Workshops 1-6. The subgoals are:
- Obtaining advanced understanding of values, variables and arrays;
- Understanding program input and output, functions and expressions;
- Understanding simple strategies like iteration, validation, sum, count, minimum, and maxi-mum plans;
- Translating simple design into JavaScript code
- The mechanics of editing, interpreting, building and running a program
- Testing a program
- Commenting source code
- Becoming con dent and comfortable with programming in small problems
Background
In online marketing, a shopping cart is a piece of e-commerce software on a web server that allows visitors to an Internet site to select items for eventual purchase, analogous to the American English term shopping cart.- In British English, it is generally known as a shopping basket, almost exclusively shortened on websites to asket-.
The software allows online shopping customers to accumulate a list of items for purchase, described metaphorically as placing items in the shopping cart- or add to cart-. Upon checkout, the software typically calculates a total for the order, including shipping and handling (i.e. postage and packing) charges and the associated taxes, as applicable.
The development of web shop systems took place directly after the Internet became a mass medium. This was a result of the launch of the browser Mosaic in 1993 and Netscape in 1994. It created

2
an environment in which web shops were possible. The Internet therefore acted as the key infras-tructure developments that contributed to the rapid di usion of the e-commerce. E-commerce (as a subset of e-business) describes all computer-aided business transactions. In 1998 a total of 11 e-business models were observed, one of which was the e-shop business model for a B2C (Business-to-consumer) business - also called the online shop-. The two terms online shop- and electronic- or e-shop- are used inter-changeably. The term online shopping- was invented much earlier in 1984; for example TV shopping often used the term before the popularity of the online method. Today the term primarily refers to the B2C transactional business model. In order to enable online shopping- a software system is needed. Since online shopping-, in the context of the B2C business model, became broadly available to the end consumer, internet-based online shops- evolved.
Although the most simple shopping carts strictly allow for an item to be added to a basket to start a checkout process (e.g. the free PayPal shopping cart), most shopping cart software provides additional features that an Internet merchant uses to fully manage an online store. Data (products, categories, discounts, orders, customers, etc.) is normally stored in a database and accessed in real time by the software.
Shopping Cart Software is also known as e-commerce software, e-store software, online store software or storefront software and online shop.
[Source from: http://en.wikipedia.org/wiki/Shopping cart software].
Introduction
HomewareCity is a fast growing family business in Toowoomba. In the past years, HomewareCity has served Toowoomba local community well. Aiming to promote customers' shopping experience and dealing with increasing demands raised by busy, aged, or disability customers, HomewareCity is going to introduce online shopping facility to the community and thus, need to develop a shopping cart system to allow customers to shop online. Against a group of talented programmers, you really want to win the contract to develop the system. But rstly you need to develop a prototype program to demonstrate the main functionality of the system, as required by HomewareCity.
To assist development of the program a template written in HTML and JavaScript has been pro-vided by HomewareCity. You can download it HERE. Note that HomewareCity has speci cally required that the program is going to be developed in JavaScript and all code should go into the
script =script section.
Functional Requirements
As the prototype for a web-based shopping cart system, the program is to be implemented in JavaScript and running on F irefox, an operating system independent web browser. Home-wareCity has speci ed the following business requirements:
1. The program should be running without errors throughout two Phases: Information Gather-ing and Information Presenting.

3
2. In Information Gathering, each time the user adds one product item to the shopping cart. The program should rst con rm with the user for willingness of shopping before proceeding to gather information of the product item in purchase.
3. When receiving an order, the program should rst prompt and ask the user to enter the product code before adding the product item to the shopping cart. If the user enters an invalid value, for example, a non-number value or a non-existing product code, the program should alert an error message on screen and then prompt the user for re-enter. The process should iterate until a valid product code is entered.
4. If the entered product code is valid, the program should then prompt the user to input the quantity value in purchase. Again, if an invalid value is input, such as a non-number value, a negative number or zero, the program should display an error message then iterate until receive a valid number for quantity.
5. After valid input of product code and quantity, the program should add the product item into the shopping cart, and then loop back to seek user con rmation for either proceeding further to add one more item or moving to the Information Presenting Phase for check-out.
6. If the user con rms not to shop anymore, the Information Gathering Phase is completed and the program then moves to Information Presenting.
7. In the Information Presenting Phase, the program prints on the web page a table containing the product items in the shopping cart, including information such as product names, prices, quantity, and cost.
8. To make the Shopping Cart System user-friendly, HomewareCity also expects the program to display some statistic information:
- The total amount for ordered items in the shopping cart;
- The average cost per item in the cart;
- The most expensive product item;
- The least expensive product item.
Respectively, Figure 1 and 2 illustrate the data ow in Information Gathering Phase and a sample result presented to the html page in Information Presenting Phase.
Arrays
Two arrays have been supplied in the template provided by HomewareCity, one for the list of prod-ucts (namely productListArr) and the other for their corresponding prices (namely priceListArr). Note that in the two arrays a product item and its corresponding price share exactly the same index in their respecting arrays1.
You need to create two arrays { one to store the product code of ordered products (namely orderedP roductCodeArr), the other to store the quantity of ordered products (namely quantityArr). Just like productListArr and priceListArr, an ordered products' code and quantity will be stored at exactly the same index in their corresponding arrays. A diagram illustrating the relationships between productListArr, priceListArr, orderedP roductCodeArr, and quantityArr is shown in Figure 3.

1Hint: there is no need for an array to store the product codes. They are just the index in productListArr.

4
Figure 1: Data Flow in Information Gathering

5
Figure 2: Sample Result of Information Presenting

Figure 3: Relationship Diagram for Arrays

6
Implementation
Task 1 - Presenting the Catalogue
In the beginning of the program, print to a table the catalogue for all products including name, code, and price, to assist users shopping. You should use a loop plan to access the data stored in productListArr and priceListArr and present it in a four-column table, like Figure 4, where each column is a set of products with code, name, and price.
Figure 4: Sample Catalogue in Display
Task 2 - A Validation Plan for Valid Product Codes
You need to implement a validation plan to get a valid input from the user for product code. An input value is considered invalid if:
- it is not a number at all;
- it is not an integer number;
- it is a negative number;
- it is a number out of range (greater than or equal to the size of productListArr).
Task 3 - A Validation Plan for Valid Quantity Values
You need to implement another validation plan to get a valid input from the user for quantity. An input value is considered invalid if:
- it is not a number at all;
- it is not an integer number;
- it is zero or a negative number;
- it is greater than 100.2

2Orders with quantity of greater than 100 will need to go wholesale and will not be accepted here by the system.

7
Task 4 - An Iteration Plan for Information Gathering Phase
You need to design a looping plan to implement the Information Gathering Phase. Refer to Func-tional Requirements and Fig. 1 for the detail of data ow in the loop. Clearly, this task should incorporate the works in Task 2 and 3.
Task 5 - A Sum Plan to Calculate the Total Cost
Your program needs to calculate the total cost for all ordered products in the shopping cart. The calculation formula is provided:
i2X
totalCost(cart) = pricei quantityi
cart
Task 6 - A Maximum Plan to Find the Most Expensive Product in Cart
Your program needs to nd the most expensive product in the shopping cart. To do it, for each of the products added in to the cart you need to retrieve the corresponding price from priceListArr, and then compare the prices one by one. Once you nd out the most expensive price, the corresponding product item in productListArr will be the most expensive product in the shopping cart.
If you have multiple products in the cart sharing the same most expensive price you can select any one of them as the most expensive product-.
Task 7 - A Minimum Plan to Find the Least Expensive Product in Cart
Your program also needs to nd the least expensive product in the shopping cart. You may adopt the the same strategy in previous task for this task. Again, if you have multiple products in the cart sharing the same least expensive price you can select any one of them as the least expensive product-.
Task 8 - An Average Plan to Calculate the Average Cost
Your program needs to be able to calculate the average cost for all product items in the shopping cart. This can be done by the total cost divided by the accumulated value of quantities:
P
i2cart pricei quantityi averageCost(cart) = P
i2cart quantityi

You should handle the Division by Zero- exception when calculating average.

8
Task 9 - Presenting the Cart
Print to a table the detailed information of shopping cart, such as product name, price, quantity, and cost. You should adopt an iteration plan to visit the elements stored in quantityArr and orderedP roductCodeArr in order to get the index to retrieve product names and prices from productListArr and priceListArr.
All currency values should be at cents in terms of precision.3
Task 10 - Presenting the Statistics
Print to an unordered list the statistic information (total cost, most expensive item, least expensive item, and average cost per unit for the ordered product items) on shopping cart.
The table and the list should be formatted like the screenshot in Figure 2. The same as that in Task 9, all currency values should be at cents in terms of precision.
Challenging Task - Duplicate Order Detection [Optional]
Note: No extra marks are gained for completion of the challenging task.
HomewareCity will appreciate it if an extra feature can be delivered to detect duplicate orders. If an ordered item has already been in the cart, the system should detect it, and then ask for user con rmation for updating the quantity or not. If the user gives a positive con rmation, the system will proceed to prompt for quantity and then replace the stored quantity by the newly entered value; otherwise, the program terminates the current product-adding process and loop back to ask user con rmation for adding a new item or not. Note that the user is not allowed to completely remove an ordered item from the shopping cart.
Program Integration Test
You need to test the program for all functionality thoroughly before delivering the program. The program should be running appropriately without any syntax and logic errors.
Non-Functional Requirements
- All code should appear in the script section in the head of the HTML document. Do not write any code in the HTML body. All functionality are delivered by JavaScript.
- In the script order your code as follows:
(a) Constants;
(b) Variables and objects (declared and initialised);
(c) Other statements.

3Round up and keep only two digits after decimal point.

9
- Variable and constant identi ers should use an appropriate convention. Identi ers should be written consistently throughout the code.
- Code is indented appropriately and grouped in blocks according to the common tasks at-tempting to.
- Appropriate comments should be added to all blocks of code. Do not simply translate the syntax into English for comments, instead, describe the purpose of the code block.
Submission
What Needs to Submit { Two Files }
1. Statement of Completeness in a le saved in .doc, .docx, .odt, .rtf or .txt format in 200-300 of your own words describes the following issues. You should rst specify the registered name of the team and all members' name and student ID on the top of the statement.
- The state of your assignment, such as, any known functionality that has not been implemented, etc. (It is expected that most teams will implement all of the functionality of this assignment.)
- Problems encountered, such as, any problems that you encountered during the as-signment work and how you dealt with them. This may include technical problems in programming and people-soft problems in team working;
- Re ection, such as, any lessons learnt in doing the assignment and suggestions to future programming projects.
2. The program in a le saved with an .html extension contains the source code implemented following the functional and non-functional requirements.
10
Marking Criteria
The assignment will be marked out of 24 and scaled down to a grade out of 12. Table 1 presents the marking criteria. If all criteria are satis ed you will receive 24 marks. If not all criteria are met, part marks may be given. Check your own submission against these criteria before you submit.
Table 1: Marking Criteria
ID REQUIREMENTS MARK

Statement of Completeness
1 The statement is in appropriate length of 200-300 of own words covering issues 1
on both programming and team working
2 The State of assignment- re ects the true state of completeness 1
3 The Problems encountered- discusses problems and dealing strategies 1
4 The Re ection- discusses learned lessons and reasonable suggestions 1
Subtotal 4

Functional Requirements
5 The program is running without any errors 1
6 Task 1 - The Catalogue is presented appropriately using an iteration plan 1
7 Task 2 (a) - User input for product code is obtained as required and parsed to 1
appropriate value type if necessary
8 Task 2 (b) - The validation plan validates product code inputs as required 1
9 Task 3 (a) - User input for quantity is obtained as required and parsed to 1
appropriate value type if necessary
10 Task 3 (b) - The validation plan validates quantity inputs as required 1
11 Task 4 (a) - Information Gathering Phase in iteration takes multiple products 1
12 Task 4 (b) - User con rmation is obtained using correct function and used as the 1
sentinel for iteration plan
13 Task 5 - The sum plan calculates the total cost correctly 1
14 Task 6 - The maximum plan nds the most expensive product in cart 1
15 Task 7 - The minimum plan nd the least expensive product in cart 1
16 Task 8 (a) - The average plan calculate the average cost correctly 1
17 Task 8 (b) - Division by Zero- exception is handled appropriately 1
18 Task 9 (a) - The cart is presented completely in table form as required 1
19 Task 10 (a) - The statistics are presented completely in unordered list as required 1
20 Task 9 (b), 10(b) - All currency values are displayed at cents in precision 1
Subtotal 16

Non-functional Requirements
21 All functionality are implemented in JavaScript. No code goes outside of the script section 1
22 Identi ers of variables and constants are following professional conventions 1
23 Constants and variables are used in calculation and expression instead of explicit values 1
24 At least ve comments are added to describe the purpose of blocks of code 1
Subtotal 4

TOTAL 24

11

Looking for answers ?