Hello, I need help with this: – Assignment Following on the success of homework 2, your mother wants you to augment the tag sale price tracking program. In addition to storing the price of each item sold, she wants to store the name of the item sold. Create a class called TagSaleItem, with the following variables (properties) and Get/Set members (functions) Double itemPrice String itemName Add a textbox to your form to input the name of the item at the same time as the price. The previous program used an array to store a list of prices. It would be awesome if this program used an array of objects to store a list of items… but we’ll get to that in a later assignment. For now the assignment is just to create a class and a single object and demonstrate how to use it (using the Get/Set methods) Code for homework 2 that is referenced: Imports System.IO Public Class FrmMain Dim prices(0) As Double ' Array to store prices of items sold Dim totalSales As Double ' Total amount of money collected Dim totalItems As Integer ' Total number of items sold Dim averageSalePrice As Double ' Average sale price Private Sub FrmMain_Load(sender As Object, a As EventArgs) Handles MyBase.Load Dim fileName As String = "sales_data.txt" If File.Exists(fileName) Then ' Open the file for reading Dim sr As New StreamReader(fileName) Dim i As Integer = 0 ' Read each line and store it in the array Do While sr.Peek() >= 0 ReDim Preserve prices(i) prices(i) = sr.ReadLine() i += 1 totalSales += prices(i - 1) totalItems += 1 Loop ' Close the file after reading sr.Close() End If ' Update the statistics in the GUI averageSalePrice = totalSales / totalItems lblTotalSales.Text = "Total Sales: " + totalSales.ToString() lblTotalItems.Text = "Total Items: " + totalItems.ToString() lblAverageSalePrice.Text = "Average Sale Price: " + averageSalePrice.ToString() End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Dim fileName As String = "sales_data.txt" ' Open the file for writing Dim sw As New StreamWriter(fileName, False) ' Write each price in the array to a new line in the file For i As Integer = 0 To prices.Length - 1 sw.WriteLine(prices(i)) Next ' Close the file after writing sw.Close() Me.Close() End Sub Private Sub btnSubmitPrice_Click(sender As Object, e As EventArgs) Handles btnSubmitPrice.Click Dim price As Double = InputBox("Enter Price: ", "Enter a Number") ' Add the price to the array and update the statistics ReDim Preserve prices(prices.Length + 1) prices(prices.Length - 1) = price totalSales += price totalItems += 1 averageSalePrice = totalSales / totalItems ' Display the statistics lblTotalSales.Text = "Total Sales: " + totalSales.ToString() lblTotalItems.Text = "Total Items: " + totalItems.ToString() lblAverageSalePrice.Text = "Average Sale Price: " + averageSalePrice.ToString() End Sub End Class

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter6: Managing Multiple Worksheets And Workbooks
Section: Chapter Questions
Problem 3.8CP
icon
Related questions
Question

Hello, I need help with this:

 – Assignment
Following on the success of homework 2, your mother wants you to augment the tag sale price tracking
program. In addition to storing the price of each item sold, she wants to store the name of the item sold.
Create a class called TagSaleItem, with the following variables (properties) and Get/Set members
(functions)
Double itemPrice
String itemName
Add a textbox to your form to input the name of the item at the same time as the price.
The previous program used an array to store a list of prices. It would be awesome if this program used
an array of objects to store a list of items… but we’ll get to that in a later assignment. For now the
assignment is just to create a class and a single object and demonstrate how to use it (using the Get/Set
methods)

 

Code for homework 2 that is referenced:

Imports System.IO

Public Class FrmMain
    Dim prices(0) As Double ' Array to store prices of items sold
    Dim totalSales As Double ' Total amount of money collected
    Dim totalItems As Integer ' Total number of items sold
    Dim averageSalePrice As Double ' Average sale price

    Private Sub FrmMain_Load(sender As Object, a As EventArgs) Handles MyBase.Load
        Dim fileName As String = "sales_data.txt"
        If File.Exists(fileName) Then

            ' Open the file for reading
            Dim sr As New StreamReader(fileName)
            Dim i As Integer = 0

            ' Read each line and store it in the array
            Do While sr.Peek() >= 0
                ReDim Preserve prices(i)
                prices(i) = sr.ReadLine()
                i += 1
                totalSales += prices(i - 1)
                totalItems += 1
            Loop

            ' Close the file after reading
            sr.Close()
        End If

        ' Update the statistics in the GUI
        averageSalePrice = totalSales / totalItems
        lblTotalSales.Text = "Total Sales: " + totalSales.ToString()
        lblTotalItems.Text = "Total Items: " + totalItems.ToString()
        lblAverageSalePrice.Text = "Average Sale Price: " + averageSalePrice.ToString()
    End Sub
    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Dim fileName As String = "sales_data.txt"

        ' Open the file for writing
        Dim sw As New StreamWriter(fileName, False)

        ' Write each price in the array to a new line in the file
        For i As Integer = 0 To prices.Length - 1
            sw.WriteLine(prices(i))
        Next

        ' Close the file after writing
        sw.Close()
        Me.Close()
    End Sub

    Private Sub btnSubmitPrice_Click(sender As Object, e As EventArgs) Handles btnSubmitPrice.Click

        Dim price As Double = InputBox("Enter Price: ", "Enter a Number")

        ' Add the price to the array and update the statistics
        ReDim Preserve prices(prices.Length + 1)
        prices(prices.Length - 1) = price
        totalSales += price
        totalItems += 1
        averageSalePrice = totalSales / totalItems

        ' Display the statistics
        lblTotalSales.Text = "Total Sales: " + totalSales.ToString()
        lblTotalItems.Text = "Total Items: " + totalItems.ToString()
        lblAverageSalePrice.Text = "Average Sale Price: " + averageSalePrice.ToString()

    End Sub
End Class

 

 

Tag Sale
Total Sales
Average Sale Price
Submit Price
Total Items
Exit
X
Transcribed Image Text:Tag Sale Total Sales Average Sale Price Submit Price Total Items Exit X
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Introduction to Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning