Psuedocode and Flowcharts assignment
Contents Phase 1: Design Concepts 2 Project Description 2 Use Cases 3 Data Dictionary 4 High Level Design Components 5 Detailed Design: Checkout 7 Diagrams 7 Design Analysis 8 Detailed Design: Product Research 9 Diagrams 9 Design – Using Pseudocode 10 Product Profit 10 Phase 2: Sequential Logic Structures 11 Design 11 Product Profit 11 Phase 3: Problem Solving with Decisions 12 Safe Discount 12 Return Customer Bonus 13 Applying Discounts 14 Phase 4: Problem Solving with Loops 15 Total order 15 Problems to Solve 16 Calculate Profits 16 Rock, Paper, Scissors 18 Number Guessing Game 20 Phase 5: Using Abstractions in Design 22 Seeing Abstractions 22 Refactoring 22
Phase 1: Design Concepts
Project Description
Although we may be late to the game, we will nevertheless join the world of e-commerce to sell our fantastic product on the Internet. To do so, we need a Web site that will allow for commerce and sales. To be quick about it, we require the following:
· Searchable inventory and shopping pages
· A shopping cart
· A place for customers to register when they make purchases
· A checkout process to make the purchase
Within this main process, there are a bunch of other needs that must be met, as follows:
· We want to track the date of the last purchase a customer make so we can offer incentives and discounts based on the last time they shopped.
· We will offer sales based on the number of different items that a person purchases.
· We will also give discounts for bulk orders a discount when a person buys many of the same item
In addition to sales feature, the solution must provide the ability to manage and research the sales of products. It must include the following:
· Must be able to add, update and remove product inventory in real time on the site
· Needs to have research capabilities to determine how well a product is selling, such as the following:
· How often the item is viewed, added to shopping carts, and then purchased
· How a price change affects sales and profit
Use Cases
From the description above, we can relate this to the following use cases, which describe how the user will interact with our system. Each use case is a set of screens that the users would interact with to accomplish something they need on the site.
In addition to the customer’s activity, the solution will allow Sales Analysts to manage and research product sales.
Data Dictionary
|
Variable Name |
Type |
Description |
|
todaysDate |
Date |
Today’s date, when the program is running |
|
creationDate |
Date |
The date the customer created their account |
|
priorPurchases |
Integer |
Number of Purchases this customer has made in the past |
|
lastPurchaseDate |
Date |
The date of the last purchase the customer made |
|
lineItemPrice |
Array |
The price of each line item the customer has added to the cart |
|
lineItemQuantity |
Array |
The quantity of each line item the customer has added to the cart |
|
membershipLevel |
Integer |
The account nature of the customer 1 – Guest 2 – Registered 3 – Preferred |
|
totalPurchaseAmount |
Double |
The cost of all the items in their current purchase |
|
salesTaxRate |
Double |
The sales tax to be charged on a purchase |
|
productCategory |
Integer |
An indicator of the category of the product 1 – Consumer Goods 2 – Electronics 3 – Clothing |
|
productPrice |
Double |
The price of the product as sold to the customer |
|
wholesalePrice |
Double |
The price at which we purchase the product |
|
numberInCarts |
Integer |
The total number of times this product has been added to a shopping cart |
|
numberOfPurchases |
Integer |
The number of times this product has been purchased |
|
allProductSalesNumbers |
Array |
A list for each product of the number of times a product has sold |
|
allProductPrices |
Array |
A list for each product of the product price |
|
allProductWholesalePrices |
Array |
A list for each product of the product wholesale price |
High Level Design Components
Our architects have created the following components to be realized by our development team in meeting the use cases above.
SearchEngine
ProductInventory
ShoppingCart
CardProcessing
Purchasing
CustomerManager
UserSecurity
Fill out the following table to describe which components are used by each use case and how each component will help realize the use case:
|
Use Case |
Component |
Services Provided |
|
Search/Browse Inventory |
ProductInventory |
Provides access to the database of inventory of all products and their descriptions and prices and such. |
|
|
SearchEngine |
Allows for searching on many criteria within the product database |
|
|
|
|
|
Register As Customer |
CustomerManager |
Create and manage customer profile and personal information |
|
|
UserSecurity |
Provide security solutions for the visitors to the site |
|
|
|
|
|
Choose Products |
<ProductSelection> |
<Allows customers to choose and select products> |
|
|
|
|
|
|
|
|
|
|
|
|
|
Checkout |
<ShoppingCart> |
<Allows customers to view items added and begin payment method via credit card or other online payment services> |
|
|
|
|
|
|
|
|
|
|
|
|
|
Apply Discounts |
<Discounts> |
<Allows customer to apply a valid promotional code given by the company to reduce the original price of a product> |
|
|
|
|
|
|
|
|
|
|
|
|
|
Manage Products |
<ManageItems> |
<Allows customers to increase, decrease or remove items from the Shopping Cart> |
|
|
|
|
|
|
|
|
|
|
|
|
|
Research Sales |
<ProductsSold> |
< The number of times this product has been purchased > |
|
|
|
|
|
|
|
|
|
|
|
|
Detailed Design: Checkout
Diagrams
We could realize this design as either structured or Object-Oriented given the following design diagrams.
calculate OrderTotal
Calculate Subtotal
bigBuyer Discount
bulkBuyer Discount
returnCustomer Bonus
daysSinceLast Purchase
Figure 1 Structure Design for calculateOrderTotal
Figure 2: Sequence Diagram for calculateOrderTotal
;Order
;DiscountManager
;Customer
;Taxes
bigBuyerDiscount()
bulkBuyerDiscount()
returnCustomerBonus()
daysSinceLastPurchase()
calculateSubtotal()
Design Analysis
Given the designs above, we need to analyze which approach we should take and how the code realization will differ.
Structure Design
· Describe the implementation of the structure design in Figure 1 and how it relates to the Checkout use case.
Figure 1 shows how discounts and bonuses are given and the criteria they are given on. There are discounts for bulk orders, big buyers, and returning customers. Through this checkout process, the discount depends on the customer and the order being purchased.
· What procedures and functions are being created in the design?
In Figure 1 above, the design shows how the customer and their purchase coincides with one another to determine a finalized price. This includes addition, i.e. shipping and tax, and subtraction i.e. discounts.
· What data would be passed between these procedures and functions?
The data that would be passed between these procedures and functions would be what type of discount you would receive if you are a Bulk-Buyer, Big-Buyer, or Returning customer. Also, purchase history and bonuses are identified through this process as well.
Object-Oriented Design
· Describe the implementation of the object-oriented design in Figure 2 and how it relates to the Checkout use case.
Figure 2 shows somewhat of a process timeline that you can expect to go through depending on what type of customer you are. For instance if you are a one-time customer you will by-pass all discounts and your order will be paid in full including taxes, whereas if you are a returning bulk-buyer you will be presented with a bulk-buyer discount.
· What methods are being created in the design?
The methods that are being created in the design are that to show the process in which the order total will be calculated. Depending on what kind of customer you are depends on your order total.
· What data would be passed between these methods?
The data that is passed between these methods is who will receive a discount and at what point in the Order Total process does the specified buyer receive their discount or if the buyer receives a discount at all.
Comparison
· How do these approaches (Structured versus OO) differ?
One big difference between both approaches is that Figure 1calculates the order total first before discounts and then Figure 2 calculates order total after all the discounts have been applied.
· How much will the detailed implementation when we get to code differ because of the high level design approach we choose?
It will differ because of the process being coded. The designs are similar but have small differences. Even though the differences are small, the codes have to process each in a different way, so that means the code implementation will be significantly different.
Detailed Design: Product Research
Diagrams
For the product research use case, take a stab at either a structured design diagram or a sequence diagram that would fulfill at least part of the functionality of the use case. We will compare what you create here to the detailed design we create through the rest of the course as a way of measuring your progress.
· Provide a diagram of your choice here to show a flow for researching products.
The exact details are flexible within the description of the functionality, so do your best to create a flow that looks like a code solution using the components above or ones you think you need. This is practice that will give you a measuring stick for your learning as we see problems later in the course related to this system.
Customer
Registration
Calculate Tool
Discount
Product
Selection
Search
Inventory
Inventory
Design – Using Pseudocode
Product Profit
Description
It is important to know the profit each product is providing to the bottom line. Given that we know the wholesale cost, the retail cost to consumers and the number of items we have sold, calculate the profit for a given product.
Pseudocode
function productProfit(productPrice : Double,
wholesalePrice : Double,
numberOfPurchases : Integer)
Return Double
Profit = (productPrice – wholesalePrice) ⃰ numberOfPurchases
End function