Problem Requirements

1 / 13
About This Presentation
Title:

Problem Requirements

Description:

The customer gets a 10% discount on all items if he/she has been a ... The tax is 6% on the discounted subtotal. First Purchase Date. Customer Information ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0

less

Transcript and Presenter's Notes

Title: Problem Requirements


1
Problem Requirements
Create a cash register form to enter customer
information and multiple items name and cost,
then display the items total, discount, subtotal,
tax and amount due. The customer gets a 10
discount on all items if he/she has been a
customer for more than 6 months, an additional
5 discount is given if they have been a customer
for longer than 18 months. The tax is 6 on the
discounted subtotal.
2
Customer Information
First Purchase Date
3
Customer Information
First Purchase Date
Item Description
Item Cost
Next Item
4
Customer Information
First Purchase Date
Item Description
Item Cost
Next Item
Final Totals
Total of items
Discount
Totals
Subtotal
Tax
Amount Due
5
Customer Information
From customer database
A Customer Since
MemberInitialDateTextBox
Item Description
Item Cost
Next Item
ItemDescriptionTextBox
ItemCostTextBox
NextItemButton
Final Totals
Total cost of items
Discount
TotalsButton
Totals
TotalCostLabel
Subtotal
DiscountAmtountLabel
Tax
SubTotalLabel
Amount Due
TaxLabel
AmountDueLabel
6
Pseudocode
  • Button Next Item
  • Parse ItemCostTextBox to itemCost
  • Add Itemcost to TotalCost
  • Clear ItemDescriptionTextBox and
    ItemCostTextBox
  • Set focus to ItemDescriptionTextBox and
    Select all
  • Button Display Totals
  • Compute Discount with a Function call passing
    TotalCost
  • Compute SubTotal TotalCost - Discount
  • Compute Tax SubTotal TaxRate
  • Compute AmountDue SubTotal Tax
  • Display results in labels as currency
  • Clear All Entry TextBoxes and set focus to First
    name

7
Code
  • Button Next Item
  • Parse itemCostDecimal Decimal.Parse(itemCostText
    Box.Text)
  • Add TotalCostDecimal ItemCostDecimal
  • Clear ItemDescriptionTestBox.Clear() and
    ItemCostTextBox.Clear()
  • Set focus and select all ItemDescriptionTextBoxF
    ocus()

  • ItemDescriptionTextBox.SelectAll()
  • Button Display Totals
  • Compute DiscoutDecimal Discount(TotalCostDecima
    l)
  • Compute SubTotalDecimal TotalCostDecimal
    DiscountDecimal
  • Compute TaxDecimal SubTotalDecimal
    TAX_RATE_Decimal
  • Compute AmountDueDecimal SubTotalDecimal
    TaxDecimal
  • Display results in labels as currency
  • Set TotalCost 0 and Clear all entry TextBoxes
    and set focus to First Name

8
Next Item Button
  • Module level variable
  • Dim TotalCostDecimal as Decimal 0D
  • Private Sub NextItemButton_Click( to VB
    generated Arguments )
  • Declare local variables
  • Dim ItemCostDecimal as Decimal
  • Try
  • Parse input numerical Values
  • ItemCostDecimal Decimal.Parse(ItemCostTextB
    ox.Text)
  • Compute values
  • TotalsDecimal ItemCostDecimal
  • Clear TextBoxes
  • ItemDescriptionTextBox.Clear()
  • ItemCostTextBox.Clear()
  • ItemDescriptionTextBox.Focus()
  • Catch AnError As Exception
  • MessageBox(AnError.Message,Error)
  • ItemCostTextBox.Focus()
  • End Try

9
Display Totals Button
  • Private TotalCostDecimal as Decimal
    module Variable
  • Declare variables and Constants
  • Dim DiscountDecimal as Decimal
  • Dim SubTotalDecimal as Decimal
  • Dim TaxDecimal as Decimal
  • Dim AmountDueDecimal as Decimal
  • Const TAX_RATE_Decimal as Decimal 0.07D
  • Calculate Values
  • DiscountDecimal Discount(TotalCostDecimal)
  • SubTotalDecimal TotalCostDecimal
    DiscountDecimal
  • TaxDecimal SubTotalDecimal TAX_RATE_Decimal
  • AmountDueDecimal SubTotalDecimal TaxDecimal

10
Totals Button
  • Try
  • Compute Values
  • DiscountDecimal Discount(TotalCostDecimal)
  • SubTotalDecimal TotalCostDecimal
    DiscountDecimal
  • TaxDecimal SubTotalDecimal TAX_RATE_Decimal
  • AmountDueDecimal SubTotalDecimal TaxDecimal
  • Format and display values
  • TotalCostLabel.Text TotalCostDecimal.ToString(C
    )
  • DiscountAmountLabel.Text DiscountDecimal.ToStrin
    g(C)
  • SubTotalLabel.Text SubTotalDecimal.ToString(C)
  • TaxLabel.Text TaxDecimal.ToString(C)
  • AmountDueLabel.Text AmountDueDecimal(C)
  • ClearTextBoxes()
  • Catch
  • Error Message, set focus and select all
  • End Try

11
ClearTextBoxes Procedure
Three possibilities
  • Private sub ClearAllBoxes()
  • FirstNameTextBox.Clear()
  • LastNameTextBox.text
  • AddressTextBox.Text String.Empty
  • etc.
  • TotalCostLabel.text String.Empty
  • etc
  • TotalCostDecimal 0
  • firstNameTextBox.Focus()

Two possibilities
12
Totals Button Code
  • Call of cuntion
  • DiscountDecimal Discount(TotalCostDecimal)
  • Function heading
  • Private Function Discount(ByVal TotalDecimal as
    Decimal) As Decimal

13
Function DiscountAmount
  • Private Function Discount(ByVal TotalDecimal as
    Decimal) as Decimal
  • 10 discount on all items if a customer for more
    than 6 months, an additional 5 discount if a
    customer longer than 18 months.
  • Const FIRST_DISCOUNT_RATE_Decimal as Decimal
    0.05DConst SECOND_DISCOUNT_RATE_Decimal As
    Decimal0.10D

The method below uses the second discount on the
discounted price. Dim MemberDate as Date
Dim MonthsDouble As Double Parse
numeric/date textboxes MemberDate
Date.Parse( MemberInitialDateTextBox.text)
Calculate Months MonthsDouble
DateDiff(DateInterval.Months, MemberDate, Today)
Discount 0 IF monthsDouble gt 6
Then Discount TotalDecimal
FIRST_DISCOUNT_RATE_Decimal EndIf IF
monthsDouble gt 18 Then Discount (TotalDecimal
-DiscountDecimal)SECOND_DISCOUNT_RATE_Decimal
EndIf End Function
Write a Comment
User Comments (0)