Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 244,288 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 969 people online right now. Registration is fast and FREE... Join Now!




suming the totals of a collection

 
Reply to this topicStart new topic

suming the totals of a collection, need hw help fast

sweetlipz
1 Dec, 2008 - 07:06 PM
Post #1

New D.I.C Head
*

Joined: 1 Dec, 2008
Posts: 16

ok heres the assignment my teacher gave me for a intro to vb.net course

Bea Frugal is a careful shopper. She always looks for the specials and coupons before making any purchases, and she keeps records of the amount of money she has saved. After a day of shopping, Bea manually adds up the coupons and discount amounts she has accumulated that day and records it in a book. She would also like to record total purchases for the day and the percentage of her savings over cost but would like to use her computer to do the work. Design and implement an application that will provide Bea with the totals she desires. As the number of transactions will vary from trip to trip, the application should request the number of transactions to be entered. Collect the paid amount and the coupon or discount amount for each transaction. Sum the amounts, calculate the savings percent and display the total purchase price (paid plus discount), the total discount amount (savings), the percentage of savings over total cost, and the total amount paid. Use a Sub procedure to collect and sum the totals, passing the total variables by reference; use a Function to calculate and return the savings percentage (pass the total cost and savings by value), and a Sub procedure to display the results (pass all totals and percentage by value). The interface should contain output labels for each total (display as currency) and one for savings percent (display as a percentage). Provide two buttons: one to allow a new set of transactions (reset) and one to exit the application. Use all of the techniques you have learned to ensure proper input handling. Name the project and solution "Coupons."


i think its a bit tuff for a intro course and pls dont badger me for being a bad student...seriously all he does is read of his powerpoint for 3 hours and now im in danger of failing the class and im panicking

i spent about 5 or 6 hours on this assignment and got absouletly no where and im pulling my hair out pls help!!

heres the code for it so far... as u can see i am having immense trouble coding it to sum the totals of the collection i have a add button to add each text entry to the collectino and then a calc button to calculate once all entrys to the collection have been entered its easy wen its like me.ampt textbox.text + me.ampttext...blah blah but i cant figure out how to add the totals together wen they in collection pls help





CODE
Public Class Form1



    Dim purchases As Collection
    Dim item As aClass






    Private Sub xResetButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xResetButton.Click
        Me.xNumofTransTextbox.Text = String.Empty
        Me.xNumofTransTextbox.Focus()
    End Sub

    Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
        Me.Close()
    End Sub

    Private Sub xNumofTransTextbox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumofTransTextbox.Click
        Me.xNumofTransTextbox.Focus()
        Me.xNumofTransTextbox.SelectAll()
    End Sub

    Private Sub xNumofTransTextbox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xNumofTransTextbox.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
        AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        purchases = New Collection
    End Sub

    
    
    Private Function GetSavingPercentage(ByVal totalcost As Decimal, ByVal savings As Decimal)
        Dim total As Decimal
        Dim discount As Decimal




    End Function

    Private Sub xEnterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xEnterButton.Click
        Dim numberofitems As Integer
        Integer.TryParse(Me.xNumofTransTextbox.Text, numberofitems)
    End Sub


    Private Sub xTotalPaidTextbox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xTotalPaidTextbox.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
                AndAlso e.KeyChar <> ControlChars.Back _
                AndAlso e.KeyChar <> "." Then
            e.Handled = True
        End If
        
    End Sub

    Private Sub xDisAmtTextbox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xDisAmtTextbox.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
                        AndAlso e.KeyChar <> ControlChars.Back _
                        AndAlso e.KeyChar <> "." Then
            e.Handled = True
        End If
        
    End Sub

    Private Sub xAddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xAddButton.Click
        item = New aClass(Me.xTotalPaidTextbox.Text, Me.xDisAmtTextbox.Text)
        purchases.Add(item)


    End Sub

    Private Sub CollectandSumtheTotals(ByVal items As aClass, ByVal total As aClass, ByVal discount As aClass, ByVal numberofitems As Integer)
        Dim item As aClass
cint(total as expression) as integer
        Dim TotalPaid As aClass = "0"
        For Each Total As aClass In purchases
            TotalPaid = Total.show
        Next

        If numberofitems <> items in purchases Then
            MsgBox("Error")
        End If




        Me.xTotSpentLabel.Text = TotalPaid.ToString("C2")
    End Sub
  


End Class


heres the class i came up with or collection or watever
CODE
Public Class aClass

    Private total As Integer
    Private discount As Integer



    Public Sub New(ByVal n As Integer, ByVal d As Integer)
        total = n
        discount = d

    End Sub

    Public Function show() As String
        Return total.ToString() + "/" + discount.ToString()
    End Function
End Class


This post has been edited by Jayman: 1 Dec, 2008 - 09:23 PM

User is offlineProfile CardPM
+Quote Post


Nykc
RE: Suming The Totals Of A Collection
1 Dec, 2008 - 07:11 PM
Post #2

That Just Happened!
Group Icon

Joined: 14 Sep, 2007
Posts: 5,908



Thanked: 33 times
Dream Kudos: 325
My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM
+Quote Post

sweetlipz
RE: Suming The Totals Of A Collection
1 Dec, 2008 - 07:22 PM
Post #3

New D.I.C Head
*

Joined: 1 Dec, 2008
Posts: 16

ok nykc its fixed and i alrdy said i tryed this for hours...so any help is appreciated
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Suming The Totals Of A Collection
1 Dec, 2008 - 09:23 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,063



Thanked: 159 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Topic title modified.
User is online!Profile CardPM
+Quote Post

sweetlipz
RE: Suming The Totals Of A Collection
1 Dec, 2008 - 10:03 PM
Post #5

New D.I.C Head
*

Joined: 1 Dec, 2008
Posts: 16

ok thx for the title change but i really need help on this...very fast

i may b willing to pay via paypal if some1 will do the whole thing for me correctly(sry if this against the rules!)
User is offlineProfile CardPM
+Quote Post

sweetlipz
RE: Suming The Totals Of A Collection
2 Dec, 2008 - 05:38 AM
Post #6

New D.I.C Head
*

Joined: 1 Dec, 2008
Posts: 16

any1 help pls? bump
User is offlineProfile CardPM
+Quote Post

magicmonkey
RE: Suming The Totals Of A Collection
2 Dec, 2008 - 06:11 AM
Post #7

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 93 times
My Contributions
The assignment is some of the worst requirements I have ever had the pleasure of reading. I will show you how to iterate through your collection and add stuff...

vb

Dim Item As aClass
Dim Total As Decimal
Dim DiscountedTotal As Decimal
Dim SavingsTotal As Decimal

For Each Item In purchases
Total += Item.total
DiscountedTotal += Item.total * (Item.discount \ 100)
Next

SavingsTotal = Total - DiscountedTotal

Debug.WriteLine(String.Format("Total before discount was {0:C}.", Total))
Debug.WriteLine(String.Format("Total after discount was {0:C}.", DiscountedTotal))
Debug.WriteLine(String.Format("Total savings was {0:C}.", SavingsTotal))


You need to make your class fields public to access them...
vb

Public Class aClass
Public total As Decimal 'Make Public and decimal datatype
Public discount As Integer 'Make Public

Public Sub New(ByVal n As Decimal, ByVal d As Integer) 'Make n decimal
total = n
discount = d
End Sub

Public Function show() As String
Return total.ToString() + "/" + discount.ToString()
End Function
End Class


This post has been edited by magicmonkey: 2 Dec, 2008 - 06:12 AM
User is offlineProfile CardPM
+Quote Post

sweetlipz
RE: Suming The Totals Of A Collection
2 Dec, 2008 - 06:26 AM
Post #8

New D.I.C Head
*

Joined: 1 Dec, 2008
Posts: 16

wow magic monkey ur info seems very useful ill try to put it to work wen i get home, at school now(no visual studios here)

i could use more info on what code to put into the class...since i have no idea

This post has been edited by sweetlipz: 2 Dec, 2008 - 06:31 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Suming The Totals Of A Collection
2 Dec, 2008 - 11:16 AM
Post #9

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,063



Thanked: 159 times
Dream Kudos: 500
Expert In: Everything

My Contributions
If you are having trouble and need help right away. Then click the Live Help link on the right side of the page.

There are plenty of experts available for a charge that can help you if you don't want to wait for a response.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 03:34PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month