You have been asked to write a Visual basics program for a retail store that wil
ID: 3852316 • Letter: Y
Question
You have been asked to write a Visual basics program for a retail store that will allow them to calculate discounts for their employees when they buy items. Discounts are based on number of years worked as well as if the employee is a manager or hourly employee. They are also allowed no discount once they have received $200 in discounts for the year.
INPUT
The application must be able to collect the following “required” information for each employee:
Name (required)
Number of years employed (required, numeric, >0)
Total amount of previous purchases before discount (required, numeric, >0)
Employee status (employee or manager)
Total of today’s purchase
OUTPUT
There are two distinct areas required for output:
For each employee display the following:
Name
Employee discount percentage
YTD Amount of discount in dollars
Total purchase today before discount
Employee discount this purchase
Total with discount
Calculate the total for all employees for today’s date
Total before discount for the day
Total after discounts applied
PROCESS
Employee discount standard
Years of Employment
Management
Hourly
1-3 Years
20%
10%
4-6 Years
24%
14%
7-10 Years
30%
20%
11-15 Years
35%
25%
More than 15 Years
40%
30%
YTD discount in dollars = total purchase before today * discount
Employee discount this purchase: total purchase today * discount if < $200. If over $200 previously no discount. If less than $200 prior to today but today takes them over $200 then only allow the amount to get them to $200.
Total with discount: Total * discount allowed
COMMAND BUTTONS
1.Calculate-Calculates each employees total with discount and displays item # 1 above
2.Next Employee-clears the employee input so the next employee sale can be entered
3.Discount Summary-Displays the summary items from item # 2 above for all employees each day (daily totals)
4.Exit
Years of Employment
Management
Hourly
1-3 Years
20%
10%
4-6 Years
24%
14%
7-10 Years
30%
20%
11-15 Years
35%
25%
More than 15 Years
40%
30%
Explanation / Answer
Here is Complete Code (Created Visual studio 2010):
Public Class Form1
Dim discountPercent As Integer
Dim empName As String
Dim workYears As Integer
Dim prevPurchaseAmount As Integer
Dim todaysPurchaseAmount As Integer
Dim status As String
Dim YTDDiscountAmt As Integer
Dim TodaysPurchaseDiscountAmt As Integer
Dim TotalwithIncludingDiscount As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
InputData()
ProcessData()
Output()
End Sub
Private Sub InputData()
'INPUT DATA TO VARIABLES
empName = txtEmpName.Text
workYears = Convert.ToInt32(txtWorkYears.Text)
prevPurchaseAmount = Convert.ToInt32(txtPrevPurchaseAmount.Text)
todaysPurchaseAmount = Convert.ToInt32(txtTodaysPurchaseAmount.Text)
If cmbEmpStatus.SelectedIndex = 1 Then
status = "MANAGER"
AssignDiscountPercent(20, 24, 30, 35, 40)
Else
status = "EMP"
AssignDiscountPercent(10, 14, 20, 25, 30)
End If
End Sub
Private Sub AssignDiscountPercent(ByVal v1 As Integer, ByVal v2 As Integer, ByVal v3 As Integer, ByVal v4 As Integer, ByVal v5 As Integer)
If workYears >= 1 And workYears <= 3 Then
discountPercent = v1
ElseIf workYears >= 4 And workYears <= 6 Then
discountPercent = v2
ElseIf workYears >= 7 And workYears <= 10 Then
discountPercent = v3
ElseIf workYears >= 11 And workYears <= 15 Then
discountPercent = v4
ElseIf workYears > 15 Then
discountPercent = v5
End If
End Sub
Private Function calcYTDDiscount() As Double
'function to calculate YTD purchase discount
Return (prevPurchaseAmount * discountPercent) / 100
End Function
Private Function calcCurrentPurchaseDiscount() As Double
'function to calculate YTD purchase discount
Return (todaysPurchaseAmount * discountPercent) / 100
End Function
Private Sub ProcessData()
YTDDiscountAmt = calcYTDDiscount()
TodaysPurchaseDiscountAmt = calcCurrentPurchaseDiscount()
Dim totalDiscount = YTDDiscountAmt + TodaysPurchaseDiscountAmt
If YTDDiscountAmt >= 200 Then
TodaysPurchaseDiscountAmt = 0
ElseIf YTDDiscountAmt < 200 And TodaysPurchaseDiscountAmt < 200 Then
TodaysPurchaseDiscountAmt = Math.Abs(YTDDiscountAmt - TodaysPurchaseDiscountAmt)
End If
TotalwithIncludingDiscount = todaysPurchaseAmount - TodaysPurchaseDiscountAmt
End Sub
Private Sub Output()
DataGridView1.ColumnCount = 6
DataGridView1.Columns(0).Name = "Name"
DataGridView1.Columns(1).Name = "Discount%"
DataGridView1.Columns(2).Name = "YTD Dc Amt"
DataGridView1.Columns(3).Name = "Prev Yr Amt"
DataGridView1.Columns(4).Name = "DC % amt"
DataGridView1.Columns(5).Name = "Total With DC"
Dim row As String() = New String() {empName, discountPercent, YTDDiscountAmt, prevPurchaseAmount, TodaysPurchaseDiscountAmt, TotalwithIncludingDiscount}
DataGridView1.Rows.Add(row)
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.