Link to home
Start Free TrialLog in
Avatar of John Buchinger
John Buchinger

asked on

Array in a arraylist

This is for homework and I'm not looking for a straight up answer, but I need clear help in the right direction.

I have an arraylist that contains several "employees" with name, id, pay, and then an array of hours worked each day of the week. I can print everything except the days of the week. I have looked at many msdn pages and various website, but I have not found how to handle this.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi John;

If you have a DateTime object for the hours worked then you can use the ToString method to display the name of the day the date represents something like this.
Dim dateName As String = DateTimeObj.ToString("XXX") '' returns the 3 character name for the day
Dim dateName As String = DateTimeObj.ToString("XXXX") '' For the complete name of the day

Open in new window

Note that the XXX or the XXXX is a alpha character. See this MSDN page for help to find out which character.
Custom Date and Time Format Strings
If Fernando's answer doesn't solve your problem, then please post HOW you are storing the employee data.  What kind of structure and/or variable types are you using here?
Avatar of John Buchinger
John Buchinger

ASKER

Here is my code:

Module Module1
    Public Class clsEmployee
        Public Property strName As String
        Public Property intID As Integer
        Public Property dblPayrate As Double
        '  Public Property arrHours(6) As Integer

        Public Sub New(ByVal Name As String, ByVal ID As Integer, ByVal Payrate As Double) ', ByVal Hours As Array)
            Me.strName = Name
            Me.intID = ID
            Me.dblPayrate = Payrate
            ' Me.arrHours = Hours
        End Sub

        Public Overrides Function toString() As String
            Return String.Format("{0} {1} {2} {3}", strName, intID, dblPayrate)
        End Function
    End Class

    Public Class ArrayListOfEmployees
        Implements IEnumerable

        Private arrEmployees As New ArrayList()

        Public Sub AddEmployee(ByRef AnEmployee As clsEmployee)
            arrEmployees.Add(AnEmployee)
        End Sub

        Public Sub ClearEmps()
            arrEmployees.Clear()
        End Sub

        Public ReadOnly Property count() As Integer
            Get
                Return arrEmployees.Count
            End Get
        End Property

        Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
            Return arrEmployees.GetEnumerator()
        End Function
    End Class

    Sub Main()
        Dim myEmps As New ArrayListOfEmployees
               Dim Hours(6) As Integer


        myEmps.AddEmployee(New clsEmployee("Sue", 103, 15.25, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Scott", 105, 15.0, {10, 10, 0, 10, 10, 10, 0}))
        myEmps.AddEmployee(New clsEmployee("Bill", 106, 12.0, {8, 8, 8, 8, 9, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Tina", 107, 16.0, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Ron", 109, 15.5, {0, 0, 9, 9, 9, 9, 9}))
        myEmps.AddEmployee(New clsEmployee("Barb", 110, 13.0, {0, 10, 0, 10, 10, 10, 0}))
        myEmps.AddEmployee(New clsEmployee("Cathy", 111, 14.5, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Al", 112, 15.0, {10, 10, 10, 10, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Dave", 133, 15.5, {0, 0, 8, 8, 8, 8, 8}))
        myEmps.AddEmployee(New clsEmployee("Haley", 134, 16.5, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Drew", 136, 12.25, {10, 10, 0, 0, 10, 10, 0}))
        myEmps.AddEmployee(New clsEmployee("John", 137, 13.0, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Mary", 138, 14.0, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Ann", 139, 15.0, {0, 0, 0, 10, 10, 10, 10}))
        myEmps.AddEmployee(New clsEmployee("Chuck", 140, 15.0, {0, 8, 8, 8, 8, 8, 0}))

             
        For Each anEmp In myEmps
            Console.WriteLine(anEmp.ToString())
        Next

        Console.ReadLine()
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The assignment wants me to place the {numbers} into an array and get the sum. And then print all of the employee info line by line
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help, but I feel kinda dumb with it being that easy
@Ark please note that this is a school assignment and experts should not be posting complete code samples.
Hi John;

The original question as you stated, "I can print everything except the days of the week."', I ask you the following question in one of my last post, "How does the assignment you were given want you to determine the day of the week? Is the 7 element array the index of that array going to determine the day of the week? For example index 0 = Sunday, 1 = Monday, .... 6 = Saturday?", in order to help you please answer the question.
Hi Fernando! I don't send complete code for the "blank" questions on homework. But author shown [almost] complete code with small errors in data types so I just corrected them.
@Ark, OK
Both gave a solution.